1

FTPS (暗黙的または明示的) 経由でリモート サーバーに接続する必要があります。FileZilla経由でサーバーに正常に接続しました。また、パブリック ftp からファイルを取得するコードをテストしました: ftp.mozilla.org 今、ftps にも同じコードが必要です。秘密鍵とキーストアに問題があります

String keyPath = "src/test/resources/keys/thekey.ppk";
        FTPSClient client = new FTPSClient();
        FileOutputStream fos = null;
        try {

            KeyStore ks = KeyStore.getInstance("JKS"); //
            FileInputStream fis = new FileInputStream(keyPath);
            ks.load(fis, "".toCharArray());//java.io.IOException: Invalid keystore format
            fis.close();
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory
                    .getDefaultAlgorithm());
            kmf.init(ks, "".toCharArray());

            System.out.println("connecting to 1.1.1.1...");
            client.setDefaultTimeout(10000);
            client.connect("1.1.1.1", 2190);
            System.out.println("loggin in...");
            System.out.println("login: " + client.login("login", "pass"));
            String remoteDir = "/pub/downloaded/";
            String remoteFileName = "testMsg.txt";
            String localFileName = "testMsg.local.txt";

            fos = new FileOutputStream(localFileName);

            System.out.println("retrieving file...");
            boolean isRetrieved = client.retrieveFile(remoteDir + remoteFileName, fos);
            System.out.print("File: " + remoteDir + remoteFileName + "; IsRetrieved: " + isRetrieved + "\n");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

キーは PuTTY 形式で生成されました。KeyStore.getInstance("JKS") には他にどのようなオプションを設定できますか。コードよりも KeyStore の部分を省略すると、client.retrieveFile の行に到達し、長時間停止します。キーをインポートするのに助けが必要です。

4

1 に答える 1

2

FTPS は FTP-over-SSL の略です。SSL は認証に X.509 証明書を使用します (現在、ほとんど使用されていないその他の方法は省略しています)。Putty は SSH/SFTP クライアント (SFTP は SSH File Transfer Protocol の略) であり、putty キーは SSH キーです。したがって、SSL 認証に SSH キーを使用することはできません。

于 2012-05-04T06:21:39.867 に答える