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

查看:112
本文介绍了如何使用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.

推荐答案

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天全站免登陆