Advertisement
Guest User

Untitled

a guest
May 7th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. String host = "166.62.85.112";
  2. int port = 22;
  3. String user = "username";
  4. String password = "password";
  5. String workingDirectory = "c:/";
  6.  
  7. Session session = null;
  8. Channel channel = null;
  9. ChannelSftp channelSftp = null;
  10.  
  11. try {
  12. JSch jsch = new JSch();
  13. session = jsch.getSession(user, host, port);
  14. session.setPassword(password);
  15. Properties config = new Properties();
  16. config.put("StrictHostKeyChecking", "no");
  17. session.setConfig(config);
  18. session.connect();
  19. channel = session.openChannel("sftp");
  20. channel.connect();
  21. channelSftp = (ChannelSftp) channel;
  22. channelSftp.cd(workingDirectory);
  23. File f = new File("D:/test.xlsx");
  24. channelSftp.put(new FileInputStream(f), f.getName());
  25. } catch (Exception ex) {
  26. ex.printStackTrace();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement