繁体   English   中英

为什么我不能将FTP客户端连接到服务器?

[英]Why can't I connect my FTP client to the server?

我做了一个FTP客户端(被动),它无法连接到服务器。 我使用的FTP服务器是Filezilla; 我只是用它来测试。 每次运行Java程序(FTP客户端)时,Filezilla断开连接,并且在Eclipse中出现以下错误: Exception in thread "main" java.io.IOException: SimpleFTP received an unknown response when connecting to the FTP server: 220-FileZilla Server version 0.9.50 beta at ftp.ftp.connect(ftp.java:25) at ftp.test.main(test.java:12)

这是FTP客户端:

package ftp;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class ftp
{

 public synchronized void connect(String host, int port, String user,
          String pass) throws IOException {
    Socket socket = new Socket(host, port);
    //  if (socket != null) {
     //     throw new IOException("SimpleFTP is already connected. Disconnect first.");
     //   }
      //  socket = new Socket(host, port);
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        BufferedWriter writer = new BufferedWriter(
            new OutputStreamWriter(socket.getOutputStream()));

        String response = reader.readLine();
        if (!response.startsWith("220-")) {
          throw new IOException(
              "SimpleFTP received an unknown response when connecting to the FTP server: "
                  + response);
        } else System.out.println("1:"+response);

        writer.write("user geek"+"\r\n");
        writer.flush();
        response= reader.readLine();
        System.out.println("2"+response);
       // response = reader.readLine();
      /*  if (!response.startsWith("331 ")) {
          throw new IOException(
              "SimpleFTP received an unknown response after sending the user: "
                  + response);
        }
        else {*/
        writer.write("PASS hello" +"\r\n");
        writer.flush();
            response= reader.readLine();
            System.out.println("3"+response);
        //}


        response = reader.readLine();
        /*if (!response.startsWith("230 ")) {
          throw new IOException(
              "SimpleFTP was unable to log in with the supplied password: "
                  + response);
        }
        else {*/
            System.out.println("4"+response);
        //}
 }

}

这是我连接的程序:

package ftp;

import java.util.Scanner;

public class test {
 private static Scanner scan;

public static void main(String args[]) throws Exception
    {

        ftp s = new ftp();
            s.connect("localhost",21,"geek", "hello");

    }

}

也尝试写我的局域网ip而不是"localhost"

... 220-FileZilla Server 0.9.50 beta版

 if (!response.startsWith("220 ")) { 

当服务器向您发送以220-开头的响应时,您期望以220<space>开头的响应。 请阅读标准以了解如何处理多行回复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM