Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
7.5k views
in Java FTP by (200 points)
I'm working on connecting to our client's server using SSH. They have our public key and I am able to connect through FileZilla, but when I try and connect using the edited code sample below, I get an authentication failure. Can you provide some insight into this issue? I generated the private/public key pair using PuTTY. The only information I have regarding their server is in the logs below (and that it is a UNIX machine).

Thanks,

import java.io.File;

import com.enterprisedt.net.ftp.FTPClientInterface;
import com.enterprisedt.net.ftp.FTPTransferType;
import com.enterprisedt.net.ftp.ssh.SSHFTPClient;
import com.enterprisedt.util.debug.Level;
import com.enterprisedt.util.debug.Logger;

public class UseSFTPWithClientValidationPublicKey {

    public static void main(String[] args) {
       
        // extract command-line arguments
        String host    = "XXX.XXX.XXX.XXX";
        String username = "username";
        String keyfile    = "D:\\SSH\\private.ppk";
        String password = "password";
        String filename = "D:\\SSH\\test.txt";
        
        // set up logger so that we get some output
        Logger log = Logger
                .getLogger(UseSFTPWithClientValidationPublicKey.class);
        Logger.setLevel(Level.ALL);
        
        try {
           com.enterprisedt.util.license.License.setLicenseDetails("LICENSEDCOMPANY", "XXX");
           
            // create client
           log.info("Creating SFTP client");
            SSHFTPClient ftp = new SSHFTPClient();

            // set remote host
            ftp.setRemoteHost(host);
            ftp.setRemotePort(22);

            // 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 private key file, user-name, and password");
            ftp.setAuthentication(keyfile, username, password);

            log.info("Turning on server validation");
            ftp.getValidator().setHostValidationEnabled(false);

            // connect to the server
            log.info("Connecting to server " + host);
            ftp.connect();

            log.info("Changing to test directory /test");
            ftp.chdir("test/053478");
            
            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();
        }
    }

    /**
     * Put a file, get it back as a copy and delete the local copy and the
     * remote copy
     * 
     * @param name
     *            original filename
     * @param ftp
     *            reference to FTP client
     */
    private static void putGetDelete(String name, FTPClientInterface ftp)
            throws Exception {
        ftp.put(name, name);
        ftp.get(name + ".copy", name);
        ftp.delete(name);
        File file = new File(name + ".copy");
        file.delete();
    }

}


Log information:

INFO [com.vesta.test.UseSFTPWithClientValidationPublicKey] 17 Dec 2009 13:37:44.455 : Creating SFTP client
DEBUG [CryptixProperties] 17 Dec 2009 13:37:44.612 : Successfully loaded the CryptixEDT properties file
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Listing CryptixEDT properties
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Alg.Alias.PaddingScheme.PKCS5Padding=PKCS#5
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Alg.Alias.Cipher.AES=Rijndael
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Msg.ok="OK"
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Msg.commandline.cancel="c"
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Mode.PCBC=com.enterprisedt.cryptix.provider.mode.PCBC
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Alg.Alias.Cipher.TripleDES=DES-EDE3
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : Alg.bitLength.HAVAL=256
ALL [CryptixProperties] 17 Dec 2009 13:37:44.612 : KeyGenerator.DES=com.enterprisedt.cryptix.provider.key.DESKeyGenerator
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : KeyGenerator.RPK=com.enterprisedt.cryptix.provider.rpk.RPKKeyGenerator
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : MessageDigest.HMAC-RIPEMD128=com.enterprisedt.cryptix.provider.mac.HMAC_RIPEMD128
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Alg.Alias.Signature.SHA-1/ElGamal=SHA-1/ElGamal/PKCS#1
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Msg.no="No"
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Alg.Alias.Signature.SHA-1/RPK=SHA-1/RPK/PKCS#1
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Debug.Level.RIPEMD160=0
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Msg.warning="Warning: "
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : MessageDigest.HMAC-HAVAL=com.enterprisedt.cryptix.provider.mac.HMAC_HAVAL
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Alg.Alias.MessageDigest.{1=3 36 3 2 1} = RIPEMD160
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Alg.OID.Cipher.RC2/CBC/PKCS#5={1 2 840 113549 3 2}
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Alg.Alias.Signature.SHA/DSA=SHA1withDSA
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Debug.Level.SPEED=0
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Signature.RawRSA=com.enterprisedt.cryptix.provider.rsa.RSASignature
ALL [CryptixProperties] 17 Dec 2009 13:37:44.627 : Alg.Alias.KeyGenerator.AES=Rijnd

3 Answers

0 votes
by (200 points)
I should add that we're using edtFTPj Pro 3.1.2.
0 votes
by (162k points)
So are you using publickey authentication with Filezilla, or password authentication? If it is the latter, can you connect using edtFTPj/PRO with password authentication?
0 votes
by (200 points)
Thanks for the reply Bruce.

I resolved the issue: I was using PuTTY to generate the public/private key pair and using the button on the GUI to dump the public key to file. However, the public key file generated had comments and line breaks in places the remote server did not seem to like. Instead I copied the public key presented in the GUI and dumped it to a file directly - no comments, no line breaks. When I did that and uploaded it to the server, the handshake worked as expected.

Categories

...