I am using the Apache commons net FTPClient to distribute files as part of batch jobs. The client is encapsulated, but roughly I issue the following method calls (i have omitted error handling, stream handling etc. for brevity):
FTPClient client = new FTPClient();
client.connect("127.0.0.1", 22);
client.login("user", "password");
client.setFileType(FTP.BINARY_FILE_TYPE);
client.changeWorkingDirectory("path/");
client.storeFile("file1.txt", new ByteArrayInputStream("hello world".getBytes()));
client.disconnect();
When I issue the commands above, The following commands are sent to the FTP server:
USER zoor
PASS ********
TYPE I
CWD path/
PORT 127,0,0,1,229,72
STOR file1.txt
And this works fine. Now, however, I am in a situation where i need to send files to a legacy system which does not support CWD
or STOR
but instead relies on CD
and PUT
, respectively..
Now my question is, how do I make the FTPClient use these commands?
I could use the sendCommand
method to send the CD
command, but I am not sure how to do this properly (and correctly) with the PUT command (given that I must send the file data also).
NOTE: I realize that there are better ways than FTP to distribute files like this, but unfortunately, my hands are bound. The recipients are using FTP and are not willing to change.
UPDATE: The legacy system is an AS/400 machine.
It occurred to me that CD and PUT are not actually FTP commands and as such the question makes little sense.. The solution (because we need it to work ASAP) is that we transfer the files to our own FTP server, and call a script via SSH on that server that transfers the files to the AS/400 machine.