0
votes

I'm trying to create a very basic Java FTP server.

The code to handle the incoming socket, accept it, and turn it into a client thread seems to work great, but for some reason it doesn't look like data is getting TO the client when I try to send the welcome message.

// outputstreamwriter for socket
out = new OutputStreamWriter(socket.getOutputStream(),"UTF-8");

// function for sending data
private void send(String s) {

   try {
      out.write(s,0,s.length());
      out.flush();
   } catch (IOException e) {
      System.out.println("Exception during send(): " + e);
   }
   System.out.println("> " + s);

}

I see in my console that it is running and trying to send the welcome message, however FileZilla (the FTP client I'm using to connect) usually sits at:

"Connection established, waiting for welcome message..."

===

Edit

The welcome message is pretty basic: send("220 WELCOME TO THE FTP SERVER");

I'm trying to include only the relevant code because it's far too much to post here. (Listening server thread which launches each client thread, etc.) The point is that it's getting to this point in the code without any problems (i.e. client thread w/ accepted socket ready-to-go) and then when I send data FileZilla appears not to see it.

1
There is not enough information here. What's in your string? Is it a valid FTP welcome message? You're not showing the code that actually sends it.RealSkeptic
please add more detail...... like @RealSkeptic says... we need to know moreTheJavaCoder16

1 Answers

1
votes

You need a CR/LF pair at the end of all communication lines. See RFC959:

The File Transfer Protocol follows the specifications of the Telnet protocol for all communications over the control connection. Since the language used for Telnet communication may be a negotiated option, all references in the next two sections will be to the "Telnet language" and the corresponding "Telnet end-of-line code". Currently, one may take these to mean NVT-ASCII and <CRLF>. No other specifications of the Telnet protocol will be cited.