【问题标题】:Could not parse response code Error in android FTP application (MalformedServerReplyException)无法解析响应代码 Android FTP 应用程序中的错误 (MalformedServerReplyException)
【发布时间】:2012-08-29 07:17:07
【问题描述】:

我想将文件从 android mobile 发送到 PC。我使用下面的代码来完成它。它抛出错误:

MalformedServerReplyException:无法解析响应代码。

请推荐

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    FtpConnect();
}

public static void FtpConnect() {
    String userName = "usr";
    String passWord = "pwd";
    String ftpAddress = "192.100.11.10"; // this isnt the ip address I was
                                            // using...
    String retrieveFromFTPFolder = "/mnt/sdcard/DCIM/Camera/Pictures/";
    String strLine;
    DataInputStream inputStream = null; 
    BufferedReader bufferedReader = null;
    FTPClient client = null;
    FTPFile[] ftpFiles = null;
    int reply;

    try {

        client = new FTPSClient();

        Log.e("","CLIENT OBJECT OK...");
        client.setListHiddenFiles(true);
        Log.e("","CLIENT HIDDEN FILES OK...");
        client.setBufferSize(1024);

        client.setConnectTimeout(60000);

        Log.e("","set CLIENT  timeout and buf size OK...");
        client.connect(ftpAddress,22); // this right here is where it fails
        Log.e("","CONNECTION OK...");

        client.login(userName, passWord);
        Log.e("","AUthentication OK...");
        client.setFileType(FTP.BINARY_FILE_TYPE);
        Log.e("","setFIletYPE OK...");
        result=client.storeFile("/mnt/sdcard/DCIM/Camera/2012-05-10 22.14.43.jpeg",inputStream);
        Log.e("RESULT","RESULT : "+result);
        if (!client.completePendingCommand()) {
            client.logout();
            client.disconnect();
            System.err.println("File transfer failed.");
            Log.e("RESULT","RESULT : "+result);
        }

    } catch (Exception e) {
        Log.e("RESULT","Exception : "+e);
        if (client.isConnected()) {
            try {
                client.logout();
                client.disconnect();
            } catch (IOException f) {
                Log.e("RESULT",""+f);
            }
        }
    } finally {
        if (client.isConnected()) {
            try {
                client.logout();
                client.disconnect();
            } catch (IOException f) {
                Log.e("RESULT",""+f);
            }
        }

它抛出的错误是

08-29 12:41:21.452: E/(2111): CLIENT OBJECT OK...
08-29 12:41:21.452: E/(2111): CLIENT HIDDEN FILES OK...
08-29 12:41:21.452: E/(2111): set CLIENT  timeout and buf size OK...
08-29 12:41:24.686: I/global(2111): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
08-29 12:41:24.694: I/global(2111): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
08-29 12:41:24.882: E/RESULT(2111): Exception : org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
08-29 12:41:24.882: E/RESULT(2111): Server Reply: SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1
08-29 12:41:25.014: E/RESULT(2111): org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
08-29 12:41:25.014: E/RESULT(2111): Server Reply: Protocol mismatch.
08-29 12:41:25.014: E/RESULT(2111): org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.

【问题讨论】:

    标签: android ftp ftp-client


    【解决方案1】:

    只是因为FTP服务器没有在指定IP启动服务器,现在可以了

    【讨论】:

    • @navy:也许他的意思是代码使用了不同的 IP(以及端口)。我犯了同样的错误,因为我正在为 FTPS 和 SFTP 编写一个包装器,所以我错误地将端口 22 用于 FTPS :-)
    猜你喜欢
    • 2013-03-15
    • 2015-07-01
    • 2019-03-16
    • 1970-01-01
    • 2023-03-20
    • 2011-04-12
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    相关资源
    最近更新 更多