我正在尝试使用代码
在FTP服务器上上传文件 try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(host);
int reply = ftpClient.getReplyCode();
if (FTPReply.isPositiveCompletion(reply)) {
ftpClient.enterLocalPassiveMode();
boolean login = ftpClient.login(user, password);
if (login) {
File localFile = new File(fileName);
InputStream inputStream = new FileInputStream(localFile);
ftpClient.appendFile("/folder/output.txt", inputStream);
}
}
} catch (Exception ioe) {
ioe.printStackTrace();
System.out.println("FTP client received network error");
}
但是,如果删除ftpClient.enterLocalPassiveMode();
,它不会在FTP服务器上上传任何内容
行,它上传一个空的output.txt文件。感谢任何有帮助的人。