如何使用 Apache Commons Net 写入远程文件? [英] How can I write to a remote file using Apache Commons Net?

查看:34
本文介绍了如何使用 Apache Commons Net 写入远程文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦程序使用 FTPClient connect() 方法连接到服务器,我如何发送字符串并将它们附加到位于远程机器上的文件中?

Once the program is connected to the server using the FTPClient connect() method, how can I send Strings and append them to a file located in the remote machine?

我读过其他帖子,但他们不使用 Apache Commons Net 库.

I have read other posts but they don't use Apache Commons Net library.

推荐答案

来自文档(您确实检查了文档,对吗?),您需要 appendFile()FTP客户端上的方法.

From the docs (you did check the docs, right?), you need the appendFile() method on the FTP client.

类似的东西

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);
}

这篇关于如何使用 Apache Commons Net 写入远程文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆