I decided by changing the logic of working with Samba Linux.
switched to fileToGet and BufferedInputStream / BufferedOutputStream
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication ("", Samba_User, Samba_Password);
// folder where to pick up
String SambaURL = "smb: //" + args [0];
// folder where to copy
File destinationFolder = new File (args [1]);
File file = new File (args [2]);
System.out.println ("Run with parameters.");
System.out.println ("Samba with files:" + SambaURL);
System.out.println ("Local folder with files for processing:" + destinationFolder);
System.out.println ("Log work to file:" + file);
System.out.println ("Reading files in the Samba folder:" + SambaURL);
// create a folder if there is none
if (! destinationFolder.exists ()) {
destinationFolder.mkdirs ();
}
SimpleDateFormat fmt = new SimpleDateFormat ("yyyyMMddHHmmssSSS_");
SimpleDateFormat dateFormat = new SimpleDateFormat ("HH: mm: ss dd.MM.yyyy");
Date date = new Date ();
int StartTime = (int) new Date (). getTime ();
String StartDateTime = dateFormat.format (date);
SmbFile dir = new SmbFile (SambaURL, auth);
for (SmbFile f: dir.listFiles ()) {
try {
child = new File (destinationFolder + "/" + f.getName ());
fileToGet = new SmbFile (SambaURL + f.getName (), auth);
fileToGet.connect ();
in = new BufferedInputStream (new SmbFileInputStream (fileToGet));
out = new BufferedOutputStream (new FileOutputStream (child));
byte [] buffer = new byte [4096];
int len = 0; // Read length
while ((len = in.read (buffer, 0, buffer.length))! = -1) {
out.write (buffer, 0, len);
}
out.flush (); // The refresh buffer output stream
try {
printlnAppen (file, "[" + StartDateTime + "]: Copied file -" + f.getName () + ".");
} catch (FileNotFoundException e) {
e.printStackTrace ();
}
} catch (Exception e) {
String msg = "The error occurred:" + e.getLocalizedMessage ();
System.out.println (msg);
} finally {
try {
if (out! = null) {
out.close ();
}
if (in! = null) {
in.close ();
}
} catch (Exception e) {
}
}