使用FTPClient connect()方法将程序连接到服务器后,如何发送字符串并将其附加到远程计算机上的文件中?
我已阅读其他帖子,但他们不使用Apache Commons Net库。
答案 0 :(得分:3)
From the docs(您确实检查了文档,对吗?),您需要FTP客户端上的appendFile()方法。
像
这样的东西String text = "...."
String remoteFileName = "..."
FTPClient ftp = ... // Already connected
try (ByteArrayInputStream local = new ByteArrayInputStream(text.toBytes("UTF-8"))) {
ftp.appendFile(remoteFilename, local);
} catch (IOException ex) {
throw new RuntimeException("Uh-oh", ex);
}