2013-12-19 34 views
5

私はftp経由でいくつかのファイルを送るために、ライブラリcommons.netでプロジェクトを作成しようとしました。しかし、私はこのエラーを受け取った私のサーバーとの接続を作成しました。commons-netはssh-2.0プロトコルと互換性があります

org.apache.commons.net.MalformedServerReplyException: Could not parse response code. 
Server Reply: SSH-2.0-OpenSSH_5.3 

私は私の接続を作成するために、このarticleを踏襲しており、official examplesと私は記事を制御してきました。

ここに私のJavaコード:

private void connect(String host, String user, String pwd) { 
     try{ 
     ftp = new FTPSClient(false); 
     //ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); 
     int reply; 

     ftp.connect(host,22);//error is here 
     reply = ftp.getReplyCode(); 
     if (!FTPReply.isPositiveCompletion(reply)) { 
      ftp.disconnect(); 
      throw new Exception("Exception in connecting to FTP Server"); 
     } 
     ftp.login(user, pwd); 
     ftp.setFileType(FTP.BINARY_FILE_TYPE); 
     ftp.enterLocalPassiveMode(); 
     }catch(Exception ex){ 
      ex.printStackTrace(); 
     } 
    } 

私が間違っていたところ、私は理解していません。

答えて

13

FTPSプロトコルはSSHで動作しません。必要なのはSFTPです。このためには、Jschライブラリ

JSch jsch = new JSch(); 
    Session session = jsch.getSession(user, host, port); 
    session.setConfig("PreferredAuthentications", "password"); 
    session.setPassword(pass); 
    session.connect(FTP_TIMEOUT); 
    Channel channel = session.openChannel("sftp"); 
    ChannelSftp sftp = (ChannelSftp) channel; 
    sftp.connect(FTP_TIMEOUT); 
+0

おかげニックで見ることができる、JSCHライブラリ –

+0

おかげでニックと正常に動作します。それは非常に便利です – Motilal

3

SFTP(SSH接続上でSSHストリームとして実行されるファイル転送)は、FTPS(SSL/TLSを使用するFTP)と同じではありません。

関連する問題