The second call to storeFileStream in FTPClient returns null

I use apache commons-net FTPClient to upload files.
I am using the storeFileStream method.
This works well for the first call, but in the second call it returns null , and .getReplyStrings() returns the command "200 PORT successfully"!
My code (this is called a method in a loop for each file):

  FileInputStream fis = null; File LF=new File(localFilePath); InputStream is = new FileInputStream(LF); for(String DP:(remoteBasepath+"/"+remoteFilePath).split("/")){ if(!client.changeWorkingDirectory(DP)){ client.makeDirectory(DP); client.changeWorkingDirectory(DP); } } for(String line:client.getReplyStrings()){ System.out.println(line); } OutputStream os = client.storeFileStream(LF.getName()); byte[] buffer = new byte[1024]; int len; System.out.println("start"); long RBUN=0L; for(String line:client.getReplyStrings()){ System.out.println(line); } while ((len = is.read(buffer)) != -1){ os.write(buffer, 0, len); os.flush(); RBUN+=len; CFPRGS.setValue(Math.round((RBUN*100/LF.length()))); } for(String line:client.getReplyStrings()){ System.out.println(line); } is.close(); os.close(); 

What is the problem?

+4
source share
1 answer

After downloading the file, I have to call:

  client.completePendingCommand(); 
+8
source

Source: https://habr.com/ru/post/1401146/


All Articles