Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use FTPSClient of org.apache.commons.net?

910595Jan 16 2012 — edited Jan 17 2012
Dear all
Currently, I found one issue while using Apache's org.apache.commons.net to connect to a FTPS site ... My code like belows:
boolean error = false;
FTPSClient ftp = null;
try
{
        ftp = new FTPSClient("SSL",true);
        ftp.setAuthValue("SSL");
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        int reply;

        ftp.connect("ftp.wpmikz.com.cn",990);
        System.out.println("Connected to ftp.wpmikz.com.cn");
        System.out.print(ftp.getReplyString());

        // After connection attempt, you should check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        if(!FTPReply.isPositiveCompletion(reply))
        {
                ftp.disconnect();
                System.err.println("FTP server refused connection.");
                System.exit(1);
        }
        ftp.login("wpmnpbatch","xxxxxxxx");
        //  ... // transfer files
        ftp.setBufferSize(1000);
        ftp.enterLocalPassiveMode();
        //ftp.setControlEncoding("GB2312");
        ftp.changeWorkingDirectory("/");
        ftp.changeWorkingDirectory("/SunShine Life/SU001SH/Interface/KZ IN/Response");
        ftp.setFileType(FTP.BINARY_FILE_TYPE);
        System.out.println("Remote system is " + ftp.getSystemName());

        String[] tmp=ftp.listNames();
        System.out.println(tmp.length);
Each time I run this code, it works fine in LOGIN and CD and even can retrieve the currenct working directory name successfully, but all the time when I execute the listNames() and listFiles(), it always report 426 error -- 426 Transfer failed. But if I use other FTP tool like FileZilla and the same user and password to login this FTP site, it always succeed. Does anyone kind to help me to solve this? Thanks in advance for any help or suggestion.

Edited by: 907592 on 2012-1-16 上午12:43

Edited by: 907592 on 2012-1-16 上午12:50
This post has been answered by gimbal2 on Jan 16 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 14 2012
Added on Jan 16 2012
7 comments
206,644 views