我正在尝试将 pdf 文件上传到 ftp 服务器。我的代码有点像这样:
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");
}
}
}
该方法显示文件已上传,该方法执行正常。并显示完成消息。但我在 ftp 中找不到该文件。这意味着文件没有上传。我的代码有什么问题。请帮忙。