hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
707 stars 180 forks source link

Copy Files Exception #765

Open scookwv opened 1 year ago

scookwv commented 1 year ago

I am getting an exception when trying to upload multiple files to an SMB share (WD My Cloud).

`SmbConfig config = SmbConfig.builder().withBufferSize(1024) .withTimeout(120, TimeUnit.SECONDS) // Timeout sets Read, Write, and Transact timeouts (default is 60 seconds) .withSoTimeout(180, TimeUnit.SECONDS) // Socket Timeout (default is 0 seconds, blocks forever) .build();

            SMBClient client = new SMBClient(config);

            try (Connection connection = client.connect("192.168.1.67")) {
                AuthenticationContext ac = new AuthenticationContext("admin", "Mustang$4".toCharArray(), null);
                Session session = connection.authenticate(ac);

                // Connect to Share
                try (DiskShare share = (DiskShare) session.connectShare(destinationShare)) {
                    info = uploadFiles(files, destinationStartingFolder, share, info, context);
                }
            }`

`private DirectoryInfo uploadFiles(File[] files, String path, DiskShare share, DirectoryInfo info, Context context) { Log.d("Files", "Size: "+ (files.length -1));

    logToFile("Uploading " + files.length + " files", context);

    for (int i = 0; i < files.length; i++)
    {
        if (!files[i].getName().equals(".thumbnails")) {
            Log.d("Files", "FileName:" + files[i].getName());

            logToFile("Uploading File: " + files[i].getName() + " Started", context);

            String filename = (files[i].getName()).split("_")[0];

            if (files[i].getName().startsWith("IMG_")) {
                filename = (files[i].getName()).split("_")[1];
            }

            if (filename.length() == 8) {
                // we have a camera file with a file name of the YYYYMMDD format
                String year = filename.substring(0, 4);
                String month = filename.substring(4, 6);

                if (!share.folderExists(path + "\\" + year + "\\" + month + "\\")) {
                    // create folder
                    if (!share.folderExists(path + "\\" + year + "\\")) {
                        // create folder
                        share.mkdir(path + "\\" + year);
                    }

                    if (!share.folderExists(path + "\\" + year + "\\" + month + "\\")) {
                        // create folder
                        share.mkdir(path + "\\" + year + "\\" + month);
                    }
                }

                try {
                    SmbFiles.copy(files[i], share, path + "\\" + year + "\\" + month + "\\" + files[i].getName(), true);
                    logToFile("Uploading File: " + files[i].getName() + " Complete", context);
                }
                catch (Exception ex) {
                    Log.e("FILE_UPLOAD", ex.getMessage());
                    logToFile("Uploading File: " + files[i].getName() + " Error", context);
                    logToFile("Uploading File: " + ex.getMessage(), context);
                }
            }

            info.IncrementFile();
        }
    }

    return info;
}`

Using the code above, I am getting this error

com.hierynomus.protocol.transport.TransportException: java.util.concurent.ExecutionException: com.hierynomus.smbj.comon.SMBRuntimeException: java.util.concurent.TimeoutException: Timeout expired.

When not using the config object with the SMBClient constructor, I get the following error:

com.hierynomus.smbj.comon.SMBRuntimeException: com.hierynomus.protocol.transport.TransportException: java.net.SocketException: Software caused connection abort

Is this something I am doing wrong in the code? Is it sending too much data to the SMB share at once? Help please!!