Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package th.in.oneauthen;
- import com.jcraft.jsch.Channel;
- import com.jcraft.jsch.ChannelSftp;
- import com.jcraft.jsch.JSch;
- import com.jcraft.jsch.JSchException;
- import com.jcraft.jsch.Session;
- import com.jcraft.jsch.SftpException;
- public class testScp {
- public static void main(String[] args)
- {
- System.out.println(System.getProperty("os.name"));
- String hostname = "161.246.35.229";
- String username = "medserv";
- String password = "MeddyCall2018";
- String copyFrom = "/home/medserv";
- String copyTo = "C:\\temp";
- JSch jsch = new JSch();
- Session session = null;
- System.out.println("Trying to connect.....");
- try {
- session = jsch.getSession(username, hostname, 22);
- session.setConfig("StrictHostKeyChecking", "no");
- session.setPassword(password);
- session.connect();
- Channel channel = session.openChannel("sftp");
- channel.connect();
- System.out.println(System.getProperty("os.name"));
- ChannelSftp sftpChannel = (ChannelSftp) channel;
- sftpChannel.get(copyFrom, copyTo);
- sftpChannel.exit();
- session.disconnect();
- } catch (JSchException e) {
- e.printStackTrace();
- } catch (SftpException e) {
- e.printStackTrace();
- }
- System.out.println("Done !!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement