我正在尝试使用FTPClient的storeFile(远程,本地)方法上传一个大文件(超过8 MB),但结果为false。它上传了一些额外的字节。以下是带输出的代码:
public class Main {
public static void main(String[] args) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("208.106.181.143");
client.setFileTransferMode(client.BINARY_FILE_TYPE);
client.login("abc", "java");
int reply = client.getReplyCode();
System.out.println("Received Reply from FTP Connection:" + reply);
if(FTPReply.isPositiveCompletion(reply)){
System.out.println("Connected Success");
}
client.changeWorkingDirectory("/"+"Everbest"+"/");
client.makeDirectory("ETPSupplyChain5.3-EvbstSP3");
client.changeWorkingDirectory("/"+"Everbest"+"/"+"ETPSupplyChain5.3-EvbstSP3"+"/");
FTPFile[] names = client.listFiles();
String filename = "E:\\Nitin\\D-Drive\\Installer.rar";
fis = new FileInputStream(filename);
boolean result = client.storeFile("Installer.rar", fis);
int replyAfterupload = client.getReplyCode();
System.out.println("Received Reply from FTP Connection replyAfterupload:" + replyAfterupload);
System.out.println("result:"+result);
for (FTPFile name : names) {
System.out.println("Name = " + name);
}
client.logout();
fis.close();
client.disconnect();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
o/p:
Received Reply from FTP Connection:230
Connected Success
32 /Everbest/ETPSupplyChain5.3-EvbstSP3
Received Reply from FTP Connection replyAfterupload:150
result:false
答案 0 :(得分:0)
首先,8 Mb文件不是一个大文件。我设法使用这个库上传大于100Mb的文件。
使用参数setFileType
在storeFile
方法之前调用BINARY_FILE_TYPE
方法。它告诉服务器你的文件不应该存储为ASCII。
最后,尝试在FileInputStream
方法之后关闭storeFile
。并捕获close
方法的结果。