Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. String SFTPHOST = "hostname";
  2. int SFTPPORT = 22;
  3. String SFTPUSER = "username";
  4. String SFTPPASS = "password";
  5. String SFTPWORKINGDIR = "directory";
  6.  
  7. Session session = null;
  8. Channel channel = null;
  9. ChannelSftp channelSftp = null;
  10.  
  11. try{
  12. String proxyHost = System.getProperty("https.proxyHost");
  13. String proxyPort = System.getProperty("https.proxyPort");
  14.  
  15. JSch jsch = new JSch();
  16. session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
  17. session.setPassword(SFTPPASS);
  18.  
  19. if(proxyHost != null && proxyPort != null) {
  20. ProxyHTTP proxy = new ProxyHTTP(proxyHost, Integer.parseInt(proxyPort));
  21. session.setProxy(proxy);
  22. }
  23. java.util.Properties config = new java.util.Properties();
  24. config.put("StrictHostKeyChecking", "no");
  25. session.setConfig(config);
  26. session.connect();
  27. channel = session.openChannel("sftp");
  28. channel.connect();
  29. channelSftp = (ChannelSftp)channel;
  30. channelSftp.cd(SFTPWORKINGDIR);
  31. Vector filelist = channelSftp.ls(SFTPWORKINGDIR);
  32. for(int i=0; i<filelist.size();i++){
  33. LsEntry entry = (LsEntry) filelist.get(i);
  34. response.getWriter().append(entry.getFilename());
  35. }
  36.  
  37. }catch(Exception ex){
  38. ex.printStackTrace();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement