| How to transfer using FTP streams |

One of the advantages of integrating FTP functionality directly into a product rather than using stand-alone FTP applications is that data can be transferred directly to and from memory. This is particularly useful when transferring dynamic content needs, such as the results of database queries and other application data.
FileTransferClient allows users to use InputStreams and OutputStreams to read and write to FTP servers, in the same way that a file or socket can be read from or written to. This is done using FileTransferClient.downloadStream() and FileTransferClient.uploadStream() methods.
To upload a string:
string s = "Hello world";
OutputStream out = ftp.uploadStream("Hello.txt");
try {
out.write(s.getBytes());
}
finally {
out.close();
}
It is essential to close the stream before performing any other FTP operations, as this completes the transfer.
Similarly, to download from an FTP server, an InputStream is used. This can be read and written anywhere:
StringBuffer s = new StringBuffer();
InputStream in = ftp.downloadStream("Hello.txt");
try {
int ch = 0;
while ((ch = in.read()) >= 0) {
s.append((char)ch);
}
}
finally {
in.close();
}
Again, it is essential to close the stream before performing any other FTP operations.