java – 在FTPClient中对storeFileStream的第二次调用返回null
作者:互联网
我正在使用apache的commons-net FTPClient来上传文件.
我正在使用storeFileStream方法.
这适用于第一次调用但在第二次调用时它返回null并且.getReplyStrings()返回“200 PORT命令成功”!
我的代码是(在每个文件的循环中称为方法):
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();
问题是什么?
解决方法:
上传文件后我应该致电:
client.completePendingCommand();
标签:java,ftp,ftp-client,apache-commons-net 来源: https://codeday.me/bug/20190609/1208134.html