SFTP connection with FTPSClient is failing

2020-03-31 05:51发布

问题:

Below code I'm trying to connect SFTP host using FTPSClient. Instead of FTP client, I'm using FTPSClient to connect. But I'm facing issue to connect.

public static void main(String[] args) throws SocketException, IOException {
        String host ="sftphost.com";
        String user = "abc";
        String pwd  = "pwd"
        final FTPSClient ftp = new FTPSClient();        
        System.out.println("host:"+host);
        ftp.connect(host,22);       
        int reply = ftp.getReplyCode();
        ftp.login(user, pwd);
}

回答1:

FTPS is not SFTP.

You cannot use Apache Commons Net FTPS client FTPSClient to connect to SFTP port 22. That's a completely different protocol.

You have to use a different library. The most commonly used SFTP library for Java is JSch.

See also Secure FTP with org.apache.commons.net.ftp.FTPClient.