0

アンドロイドモバイルから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.
4

1 に答える 1

0

FTP サーバーが指定された IP でサーバーを起動しなかったためです。現在は問題ありません。

于 2012-08-29T13:58:44.533 に答える