Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7k views
in Java FTP by (160 points)
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

4 Answers

0 votes
by (162k points)
Uncomment this line:

ftp.getValidator().setHostValidationEnabled(false);

You aren't loading the server's public key so validation is failing.
0 votes
by (160 points)
thank for reply.

i get this error when i have comment off the validator

INFO [com.mibs.ftp.SFTPConnectToServer] 22 Aug 2009 01:21:28.356 : Creating SFTP client
here 1
INFO [puretls] 22 Aug 2009 01:21:28.557 : PureTLS debug level=0
INFO [LicensePropertiesBase] 22 Aug 2009 01:21:28.771 : Licence expiry date: 17 Sep 2009
INFO [LicensePropertiesBase] 22 Aug 2009 01:21:28.771 : Trial licence
here 2
INFO [com.mibs.ftp.SFTPConnectToServer] 22 Aug 2009 01:21:28.795 : Loading client private-key from C:\Users\admin\.ssh\bkr_dsa
INFO [com.mibs.ftp.SFTPConnectToServer] 22 Aug 2009 01:21:28.795 : Setting user-name, private key file and password
INFO [OpenSSHPrivateKeyFormat] 22 Aug 2009 01:21:28.837 : Unpacking OpenSSH formatted private key
INFO [OpenSSHPrivateKeyFormat] 22 Aug 2009 01:21:28.839 : DSA private key
INFO [com.mibs.ftp.SFTPConnectToServer] 22 Aug 2009 01:21:28.846 : Connecting to server 10.1.3.51
here 3
INFO [SCPClient] 22 Aug 2009 01:21:28.850 : SCPClient settings validated.
INFO [TransportProtocolCommon] 22 Aug 2009 01:21:28.920 : Timeout=60000
INFO [TransportProtocolCommon] 22 Aug 2009 01:21:28.924 : Wait for state update timeout=60000
INFO [TransportProtocolCommon] 22 Aug 2009 01:21:28.925 : Wait for state update timeout=60000
INFO [cryptix] 22 Aug 2009 01:21:28.966 : GLOBAL_TRACE=false
INFO [cryptix] 22 Aug 2009 01:21:28.966 : GLOBAL_DEBUG=false
INFO [cryptix] 22 Aug 2009 01:21:28.966 : GLOBAL_DEBUG_SLOW=false
INFO [TransportProtocolCommon] 22 Aug 2009 01:21:28.969 : Wait for state update timeout=60000
INFO [DhGroup1Sha1] 22 Aug 2009 01:21:28.974 : Starting client side key exchange.
com.enterprisedt.net.j2ssh.SshException: The SFTP Subsystem could not be initialized
   at com.enterprisedt.net.j2ssh.SshClient.openSftpChannel(Unknown Source)
   at com.enterprisedt.net.j2ssh.SftpClient.<init>(Unknown Source)
   at com.enterprisedt.net.j2ssh.SshClient.openSftpClient(Unknown Source)
   at com.enterprisedt.net.j2ssh.SshClient.openSftpClient(Unknown Source)
   at com.enterprisedt.net.ftp.ssh.SSHFTPClient.connect(Unknown Source)
   at com.mibs.ftp.SFTPConnectToServer.main(SFTPConnectToServer.java:66)
0 votes
by (162k points)
Set logging to the ALL level and email support with the zipped log file
0 votes
by (162k points)
he server isn't responding to the SSH_FXP_INIT message, which is strange.

Could you try our version of Filezilla and send us the log file:

- Download http://www.enterprisedt.com/tools/LogZilla.zip
- Unzip
- Run Filezilla.exe

That should give us some useful information. Have you successfully connected with any other SFTP client?

Categories

...