日期:2014-05-20  浏览次数:21350 次

java commons.net.ftp.FTPClient 报Could not parse response code
本帖最后由 wangjinwei6912 于 2011-07-12 18:20:22 编辑

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.TimeZone;

import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPClientConfig;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

public class RemoteFileUtil {
    public void dologin() {    
        try {    


            //链接到ftp服务器    
         ftpClient = new FTPClient();
         ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
            ftpClient.connect("10.32.65.26",22);  
            ftpClient.login("root", "xwtech83");    
            System.out.println("登录成功.");    
                
            FTPFile[] remoteFiles = ftpClient.listFiles("/root");    
            System.out.println("目录" + remoteDir + "下的文件:");    
            if(remoteFiles != null) {    
                for(int i=0;i<remoteFiles.length;i++) {
                 String name = remoteFiles[i].getName();    
                 System.out.println(name + ":\t\t" + name);    
                }
             }    
        } catch (Exception e){    
            e.printStackTrace();    
        } 
    } 
    public static void main(String[] args) {
     remoteFile.dologin();
}


org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
Server Reply: SSH-2.0-OpenSSH_4.3
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:315)
at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:364)
at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:540)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:178)