Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String SFTPHOST = "hostname";
- int SFTPPORT = 22;
- String SFTPUSER = "username";
- String SFTPPASS = "password";
- String SFTPWORKINGDIR = "directory";
- Session session = null;
- Channel channel = null;
- ChannelSftp channelSftp = null;
- try{
- String proxyHost = System.getProperty("https.proxyHost");
- String proxyPort = System.getProperty("https.proxyPort");
- JSch jsch = new JSch();
- session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
- session.setPassword(SFTPPASS);
- if(proxyHost != null && proxyPort != null) {
- ProxyHTTP proxy = new ProxyHTTP(proxyHost, Integer.parseInt(proxyPort));
- session.setProxy(proxy);
- }
- java.util.Properties config = new java.util.Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- session.connect();
- channel = session.openChannel("sftp");
- channel.connect();
- channelSftp = (ChannelSftp)channel;
- channelSftp.cd(SFTPWORKINGDIR);
- Vector filelist = channelSftp.ls(SFTPWORKINGDIR);
- for(int i=0; i<filelist.size();i++){
- LsEntry entry = (LsEntry) filelist.get(i);
- response.getWriter().append(entry.getFilename());
- }
- }catch(Exception ex){
- ex.printStackTrace();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement