我正在尝试将文件上传到FTP服务器
正如我在How do you upload a file to an FTP server?找到的那样,我有这段代码:
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("IP");
client.login("user", "pwd");
client.changeWorkingDirectory("/a/b/c/");
// Create an InputStream of the file to be uploaded
String filePath = file.getPath();
fis = new FileInputStream(filePath);
String fileName = file.getName();
// Store file to server
client.storeFile(fileName, fis);
client.logout();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
当我运行它时,文件会在预期的位置创建,但它是空的(0 kb)
写作过程也需要很长时间......
我做错了什么?