Last active
August 29, 2015 13:56
-
-
Save raghavj1991/8864424 to your computer and use it in GitHub Desktop.
Download feature from amazon - ec2 (remote directory) to local directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sapient.iota | |
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; | |
public class FileDownload { | |
public void download() throws JSchException { | |
JSch jsch=new JSch(); | |
jsch.addIdentity("THE AMAZON PRIVATE KEY THAT YOU WILL NEED"); | |
Session session=jsch.getSession("amazon_user", "ip", sftpport); | |
java.util.Properties config = new java.util.Properties(); | |
config.put("StrictHostKeyChecking", "no"); | |
session.setConfig(config); | |
session.connect(); | |
Channel channel = session.openChannel("sftp"); | |
channel.connect(); | |
ChannelSftp channelSftp = null; | |
channel = session.openChannel("sftp"); | |
channel.connect(); | |
channelSftp = (ChannelSftp)channel; | |
try { | |
channelSftp.cd("the directory where files are located"); | |
channelSftp.get("the name of the file you want to download","local directory name"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
channel.disconnect(); | |
session.disconnect(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment