FTPSClient returns MalformedServerReplyException: cannot parse response code

30,818

Since you are connecting to an SSH server using FTP client. FTPS and SFTP are two different protocols.

Both WinSCP and Filezilla works fine because they supports SFTP.

Share:
30,818
bouncingHippo
Author by

bouncingHippo

where code bounces off me - literally!

Updated on July 10, 2022

Comments

  • bouncingHippo
    bouncingHippo almost 2 years

    I have an SFTP connection set up. I used WinCSP and Filezilla and the test server is working no problem. The java code is from the apache commons-net 2.0 and it gives me the unexpected error

    Code

    private String ftpServer="XXX.xx.x.XX";
    private int ftpPort=99;
    private String ftpUserName="myUserName";
    private String ftpPassword="myPassword";
    
    FTPSClient ftp = null;
            try{
                ftp = new FTPSClient();
                ftp.connect(hostname, port)
            } catch (Exception e){
               Logger.debug(e)
            }
    

    Stacktrace

    Server reply:SSH-2.0-WeOnlyDo-wodFTPD 2.3.6.165
    org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:315)
        at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:364)
        at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:540)
        at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:167)
        at org.apache.commons.net.SocketClient.connect(SocketClient.java:178)
        at myHomeFtpService.getFtpConnection(HomeFtpService.java:40)
    
  • bouncingHippo
    bouncingHippo about 11 years
    if i were to change the SFTP server to a FTPS server. Will it work without changing my Java code using the FTPS class?
  • Raymond Tau
    Raymond Tau about 11 years
    As FTPS is more complex then FTP, some changes may still be necessary, such as implicit/explicit mode. If your connection will goes through some firewall, you may want to explicitly disable encryption when sending the PORT/PASV command to allow firewall to see the port you will use and allow that or you need to force the FTP data connection to go through some port.
  • bouncingHippo
    bouncingHippo about 11 years
    what if i have to use an SFTP test server, are there any Java libraries I can use to connect in apache-commons?
  • Raymond Tau
    Raymond Tau about 11 years
    I don't aware of any from apache-commons. For SFTP library, please take a look at this question: stackoverflow.com/questions/14617. Personally, I am quite satisfied with schmizz.net/sshj.