When I'm using cmd
to put a file into AS400, after connecting with ftp
, I went like this:
ftp cd /home
ftp prompt 1
ftp ASC
ftp QUOTE TYPE C 1252
ftp mput *
ftp bye
Everything is working fine. The file is well encoded. Now, when I'm trying to do the same in Java. I am able to put the file, but it is not well encoded. I'm really stuck. Could someone help me out..
This is my Java code:
FTP ftp = this.SABFTPConnection();
ftp.cd(sabConfig.getDirectory());
ftp.setDataTransferType(FTP.BINARY);
ftp.issueCommand("prompt 1");
ftp.issueCommand("ASC");
ftp.issueCommand("QUOTE TYPE C 1252");
File io = new File(file);
boolean done = ftp.put(io, io.getName());
if (done) {
Log.getLog(SABData.class).info("file "+ io.getName() +" successfuly uploaded");
collected = true;
}
The FTP.issueCommand
sends FTP protocol command to the server.
There's no prompt 1
command in FTP protocol. The prompt
is ftp
client command that turns off interactive prompting. It makes no sense to try to replicate that in your Java code, as it does no prompting.
There's no ASC
command in FTP protocol. The asc[ii]
is ftp
client command that switches to ASCII transfer mode. That goes against the ftp.setDataTransferType(FTP.BINARY)
in your code.
Also the asc
sends TYPE A
command to the server. And you are sending TYPE C ...
later, the effect of asc
/TYPE A
is cancelled anyway. So the the asc
is redundant.
The quote
is an ftp
client command that sends its arguments as a command to the FTP server. So you want to send TYPE C 1252
, not QUOTE TYPE C 1252
.
So basically all your FTP.issueCommand
calls are wrong and they all fail. You would know, had you checked their return value.