Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.