hi,
i have setup a linux environment in vmware, and try to transfer some file to linux using the classes which being code in eclipse(vista).
I have generate the dsa key using puttygen and upload the public key in linux server and cat it into authorized_keys.
import java.io.File;
import com.enterprisedt.net.ftp.FTPClientInterface;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.ssh.SSHFTPAlgorithm;
import com.enterprisedt.net.ftp.ssh.SSHFTPClient;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;
public class SFTPConnectToServer {
public static void main(String[] args) {
// extract command-line arguments
String host = "10.1.1.17";
String username = "<ssh username>";
String password = "<passphase>";
//String keyfile = "/home/oracle/.ssh/bkr_key.pub";
String keyfile = "C:\\Users\\admin\\Desktop\\id_rsa"; //private key
String filename = "SFTPconnectToServer.java";
// set up logger so that we get some output
Logger log = Logger.getLogger(SFTPConnectToServer.class);
Logger.setLevel(Level.INFO);
try {
// create client
log.info("Creating SFTP client");
System.out.println("here 1");
SSHFTPClient ftp = new SSHFTPClient();
System.out.println("here 2");
// set remote host
ftp.setRemoteHost(host);
// the client's public key file must be in authorized_keys or
// the equivalent on the server
log.info("Loading client private-key from " + keyfile);
log.info("Setting user-name, private key file and password");
ftp.setAuthentication(keyfile, username, password);
//log.info("Turning off server validation");
//ftp.getValidator().setHostValidationEnabled(false);
// connect to the server
log.info("Connecting to server " + host);
System.out.println("here 3");
ftp.connect();
System.out.println("here 4");
log.info("Setting transfer mode to ASCII");
ftp.setType(FTPTransferType.ASCII);
putGetDelete(filename, ftp);
log.info("Successfully transferred in ASCII mode");
// Shut down client
log.info("Quitting client");
ftp.quit();
log.info("Example complete");
} catch (Exception e) {
e.printStackTrace();
}
}
private static void putGetDelete(String name, FTPClientInterface ftp)
throws Exception {
ftp.put(name, name);
}
}
output from eclipse:
INFO [com.mibs.ftp.SFTPConnectToServer] 21 Aug 2009 14:04:55.473 : Creating SFTP client
here 1
INFO [puretls] 21 Aug 2009 14:04:55.680 : PureTLS debug level=0
INFO [LicensePropertiesBase] 21 Aug 2009 14:04:55.883 : Licence expiry date: 17 Sep 2009
INFO [LicensePropertiesBase] 21 Aug 2009 14:04:55.884 : Trial licence
here 2
INFO [com.mibs.ftp.SFTPConnectToServer] 21 Aug 2009 14:04:55.908 : Loading client private-key from C:\Users\admin\Desktop\BMM Corporate Desktop\BKR Autopay Src\bin\com\mibs\ftp\id_rsa
INFO [com.mibs.ftp.SFTPConnectToServer] 21 Aug 2009 14:04:55.908 : Setting user-name, private key file and password
INFO [OpenSSHPrivateKeyFormat] 21 Aug 2009 14:04:55.952 : Unpacking OpenSSH formatted private key
INFO [cryptix] 21 Aug 2009 14:04:56.024 : GLOBAL_TRACE=false
INFO [cryptix] 21 Aug 2009 14:04:56.024 : GLOBAL_DEBUG=false
INFO [cryptix] 21 Aug 2009 14:04:56.024 : GLOBAL_DEBUG_SLOW=false
INFO [OpenSSHPrivateKeyFormat] 21 Aug 2009 14:04:56.071 : RSA private key
INFO [com.mibs.ftp.SFTPConnectToServer] 21 Aug 2009 14:04:56.074 : Connecting to server 10.1.1.17
here 3
INFO [SCPClient] 21 Aug 2009 14:04:56.077 : SCPClient settings validated.
INFO [TransportProtocolCommon] 21 Aug 2009 14:04:56.164 : Timeout=60000
INFO [TransportProtocolCommon] 21 Aug 2009 14:04:56.170 : Wait for state update timeout=60000
INFO [TransportProtocolCommon] 21 Aug 2009 14:04:56.171 : Wait for state update timeout=60000
INFO [TransportProtocolCommon] 21 Aug 2009 14:04:56.201 : Wait for state update timeout=60000
INFO [DhGroup1Sha1] 21 Aug 2009 14:04:56.204 : Starting client side key exchange.
ERROR [TransportProtocolOutputStream] 21 Aug 2009 14:04:56.334 : sendMessage() failed: Socket closed (state=5)
ERROR [TransportProtocolOutputStream] 21 Aug 2009 14:04:56.334 : sendMessage() failed: Socket closed (state=5)
com.enterprisedt.net.j2ssh.transport.kex.KeyExchangeException: The host signature is invalid or the host key was not accepted!
at com.enterprisedt.net.j2ssh.transport.TransportProtocolClient.performKeyExchange(Unknown Source)
at com.enterprisedt.net.j2ssh.transport.TransportProtocolCommon.beginKeyExchange(Unknown Source)
at com.enterprisedt.net.j2ssh.transport.TransportProtocolCommon.A(Unknown Source)
at com.enterprisedt.net.j2ssh.transport.TransportProtocolCommon.startBinaryPacketProtocol(Unknown Source)
at com.enterprisedt.net.j2ssh.transport.TransportProtocolCommon.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
ERROR [TransportProtocolCommon] 21 Aug 2009 14:04:56.345 : The Transport Protocol thread failed : socket closed
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.BufferedInputStream.read1(BufferedInputStream.ja