close

Here is the complete source code of an example using JSch without having to worry about the ssh key checking.

JSch is a pure Java implementation of SSH2.
JSch allows you to connect to an sshd server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs. JSch is licensed under BSD style license.

 

import com.jcraft.jsch.*;
publicclassTestJSch{
publicstaticvoid main(String args[]){
JSch jsch = newJSch();
Session session =null;

try{ session = jsch.getSession("username","127.0.0.1",22); session.setConfig("StrictHostKeyChecking","no"); session.setPassword("password"); session.connect();Channel channel = session.openChannel("sftp"); channel.connect();ChannelSftp sftpChannel =(ChannelSftp) channel; sftpChannel.get("remotefile.txt","localfile.txt"); sftpChannel.exit(); session.disconnect();
}
catch(JSchException e)
{ e.printStackTrace();
}
catch(SftpException e){ e.printStackTrace();
}
}
}
arrow
arrow

    Jason Wang 發表在 痞客邦 留言(0) 人氣()