如何使用Apache Commons Net写入远程文件?

时间:2016-03-28 16:43:22

标签: java ftp remote-access apache-commons

使用FTPClient connect()方法将程序连接到服务器后,如何发送字符串并将其附加到远程计算机上的文件中?

我已阅读其他帖子,但他们不使用Apache Commons Net库。

1 个答案:

答案 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);
}
相关问题