[英]How can I write to a remote file using Apache Commons Net?
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? 使用FTPClient connect()方法将程序连接到服务器后,如何发送字符串并将其附加到远程计算机中的文件中?
I have read other posts but they don't use Apache Commons Net library. 我已阅读其他帖子,但他们不使用Apache Commons Net库。
From the docs (you did check the docs, right?), you need the appendFile() method on the FTP client. 从文档 (您确实检查了文档,对吗?),您需要FTP客户端上的appendFile()方法。
Something like 就像是
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.