It is possible to stream directly to the FTP server, but FileInputStream is not the right class to do so -- it always reads from a local file.
The simplest way to do this in your case may be to use
client.storeFileStream(remoteName)
This method returns an output stream you can write to (instead of sucking up all the data from a given input stream), which seems to be a more natural fit for your case.
Example:
OutputStream os = client.storeFileStream("theObject");
ObjectOutputStream oos = new ObjectOutputStream(os);
// write your object to oos here,
// then close everything.
An alternative that uses the same client method as in your example but no file would be to first write the object to a ByteArrayOutputStream
, then create a ByteArrayInputStream
from getBytes()
, and hand that over to the ftp client.
BTW: The Object stream in your code can be omitted -- you can use the file stream directly:
FileInputStream fin = new FileInputStream(someVariableContainingObject);
client.storeFile("theObject", fin);
// ...