connect to SFTP using java

后端 未结 6 1670
野趣味
野趣味 2021-01-07 09:33

I need help with connection to SFTP server? Does anybody have working code?

I found something like this

package test.JSch;

import com.jcraft.jsch.*;         


        
6条回答
  •  一整个雨季
    2021-01-07 10:10

    I was having the same problem with a shell connection. The solution was to increase the timeout, in my case 5000 msec was enough

    JSch jsch = new JSch();
    Session session = jsch.getSession(USERNAME, HOSTNAME, SSH_PORT);
    session.setPassword(PASSWORD);
    Hashtable config = new Hashtable();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect(5000);
    

提交回复
热议问题