简体   繁体   English

如何使用Apache Commons Net写入远程文件?

[英]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.

相关问题 如何使用apache commons net ftp更改ftp服务器上文件的权限? - How can I change permissions of a file on a ftp server using apache commons net ftp? 爪哇| Apache Commons CSV | 如何使用 utf-8-bom 编写 csv 文件? - Java | Apache Commons CSV | How can i write a csv file with utf-8-bom? 无法使用TFTPClient发送文件(Apache Commons Net库) - Can't Send File using TFTPClient (Apache Commons Net library) 使用 UCanAccess 和 Apache Commons Net 从远程服务器中的数据库读取 - Reading from a Database in a remote Server using UCanAccess and Apache Commons Net 如何使用Apache Commons解压缩TAR文件 - How to untar a TAR file using Apache Commons 如何使用 apache commons vfs 从 Windows 读取远程文件到 Linux? - How to read remote file from Windows to Linux with apache commons vfs? 使用Apache Commons Imaging将EXIF数据写入TIFF文件 - Write EXIF data to TIFF file using Apache Commons Imaging 使用org.apache.commons.logging写日志文件 - Write log file using org.apache.commons.logging 我无法使用apache-commons-net TelnetClient禁用echo选项 - I can't disable echo option using apache-commons-net TelnetClient 使用commons net 3.0 api(org.apache.commons.net)在ftp服务器上上传文件时出现问题 - Problem in Uploading file on ftp server using commons net 3.0 api (org.apache.commons.net )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM