Hodhod
Hodhod

Reputation: 17

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

I've made a FTP client (passive) that doesn't can't connect to a server. The FTP server I'm using is Filezilla; I'm just using it for testing. Every time I run the java program (FTP client) Filezilla disconnects and I get these errors in 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)

This is the FTP client:

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);
        //}
 }

}

And this is the program where I connect:

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");

    }

}

Have also tried to write my lan ip instead of "localhost"

Upvotes: 0

Views: 1511

Answers (1)

Steffen Ullrich
Steffen Ullrich

Reputation: 123260

... 220-FileZilla Server version 0.9.50 beta

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

You are expecting a response starting with 220<space> while the server sends you a response starting with 220-. Please read the standard to learn how to deal with multi-line replies.

Upvotes: 2

Related Questions