Advertisement
Guest User

Untitled

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