1

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.

chris
  • 2,490
  • 4
  • 32
  • 56

1 Answers1

3

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);
}
Moose Morals
  • 1,628
  • 25
  • 32
  • Thanks a lot! One more question arises, why putting "UTF-8" and what difference does it make? Thanks again. – chris Mar 28 '16 at 20:19
  • "UTF-8" is the character set that the remote end will use when its appending your string. I picked it as a good default, but you'll want to check your local environment. – Moose Morals Mar 28 '16 at 20:21