与 FTPSClient 的 SFTP 连接失败

SFTP connection with FTPSClient is failing

下面的代码我正在尝试使用 FTPSClient 连接 SFTP 主机。我没有使用 FTP 客户端,而是使用 FTPSClient 进行连接。但我面临连接问题。

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);
}

FTPS is not SFTP.

您不能使用 Apache Commons Net FTPS 客户端 FTPSClient 连接到 SFTP 端口 22。这是一个完全不同的协议。

您必须使用不同的库。 Java 最常用的 SFTP 库是 JSch.

另见 Secure FTP with org.apache.commons.net.ftp.FTPClient