How can I write to a remote file using Apache Commons Net?

廉价感情. 提交于 2019-12-11 04:45:08

问题


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?

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


回答1:


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

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


来源:https://stackoverflow.com/questions/36266728/how-can-i-write-to-a-remote-file-using-apache-commons-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!