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.issueCommandsends FTP protocol command to the server.There's no
prompt 1command in FTP protocol. Thepromptisftpclient 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
ASCcommand in FTP protocol. Theasc[ii]isftpclient command that switches to ASCII transfer mode. That goes against theftp.setDataTransferType(FTP.BINARY)in your code.Also the
ascsendsTYPE Acommand to the server. And you are sendingTYPE C ...later, the effect ofasc/TYPE Ais cancelled anyway. So the theascis redundant.The
quoteis anftpclient command that sends its arguments as a command to the FTP server. So you want to sendTYPE C 1252, notQUOTE TYPE C 1252.So basically all your
FTP.issueCommandcalls are wrong and they all fail. You would know, had you checked their return value.