I am trying to use an SSH key with Jsch to copy a file via SFTP from one
machine to another. On the remote machine I have done:
$ssh-keygen -t rsa
<hit enter twice for blank passphrase>
I then end up with id_rsa and id_rsa.pub inside .ssh on the remote
machine. I copy these files to the local machine, which is where the java
program is running. This is my code:
static public final String sshuser = "<redacted>";
static public final String sshhost = "<redacted>";
static public final String privatesshkey = "id_rsa";
public boolean transferZipFile(String filename){
boolean success = true;
try{
JSch jsch = new JSch();
jsch.addIdentity(privatesshkey);
Session session = jsch.getSession(sshuser,sshhost,sshport);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking","no");
session.setConfig(config);
session.connect();
Channel channel = session.openChannel("sftp");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect();
ChannelSftp c = (ChannelSftp) channel;
c.put(filename,"/data/");
c.exit();
session.disconnect();
}catch(Exception e){
System.out.println("File transfer failed");
e.printStackTrace();
success = false;
}
return success;
}
And I am getting an exception:
com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:484)
at com.jcraft.jsch.Session.connect(Session.java:162)
at Synchronizer.transferZipFile(Synchronizer.java:185)
at Synchronizer.logoff(Synchronizer.java:137)
at Synchronizer.main(Synchronizer.java:61)
Any help appreciated, thanks!
Sincerely,
Ben May
Senior Research Analyst
Herbert Irving Comprehensive Cancer Center
212-851-4772
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users