How can I write to a remote file using Apache Comm

2019-08-10 07:31发布

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条回答
闹够了就滚
2楼-- · 2019-08-10 08:19

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);
}
查看更多
登录 后发表回答