[英]Using Apache Commons File Upload
I am trying to upload a pdf file to ftp server. 我正在尝试将pdf文件上传到ftp服务器。 My code is somewhat like this:
我的代码有点像这样:
public void pdfUpload(String ticket, JLabel message) {
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("www.mydomain.com", 21);
client.login("user", "userpass");
client.setFileType(FTP.BINARY_FILE_TYPE); // optional
String FileName = ticket.replace("/", "_");
File fil = new File("pdf\\"+FileName+".pdf");
message.setText(FileName+".pdf is being uploaded... Please wait" );
fis = new FileInputStream(fil);
String remoteFile = fil.getName();
client.storeFile(remoteFile, fis);
client.logout();
message.setText("File Uploaded sccessfully");
}
catch (IOException e) {
message.setText("Failed to upload pdf file"+e);
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
message.setText("Failed to upload pdf file");
}
}
}
The method shows that the file is uploaded, The method executes fine. 该方法表明文件已上传,该方法执行良好。 and shows the completion message.
并显示完成消息。 But I cannot find the file in ftp.
但是我在ftp中找不到文件。 It means the file is not uploaded.
这表示文件未上传。 What is wrong with my code.
我的代码有什么问题。 Please help.
请帮忙。
Try calling enterLocalPassiveMode after login. 登录后尝试调用enterLocalPassiveMode。
It could be many things, as FTP servers are unpredictable little monsters, but that's what it smells like to me. 可能有很多事情,因为FTP服务器是不可预测的小怪物,但这对我来说就像是。
It doesn't look like your File path would be valid on the remote system as a file name, or it isn't storing it as expected based upon the file path name format. 看起来您的文件路径在远程系统上不能作为文件名有效,或者根据文件路径名格式未按预期存储。 Try using just the file name without the "pdf\\\\" prefix when saving to the remote system.
保存到远程系统时,请尝试仅使用不带“ pdf \\\\”前缀的文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.