Trouble with FTP input

I'm writing an FTP client based on a generic socket example I found. I'm not sure if this is a good idea or not. I'm getting a few lines of data from the server, but I was expecting to see the username prompt too.

Here's my code...

public void run()

{

Socket clientSocket = null;

InputStreamReader in = null;

BufferedReader data = null;

PrintWriter out = null;

String temp = "";

setCursor(new Cursor(Cursor.WAIT_CURSOR));

try

{

for(int i = 0; i < 80; i++) cbuff = ' ';

lblResult.setText("Contacting "+txtServer.getText()+" ...");

clientSocket = new Socket(txtServer.getText(), jftp_port);

out = new PrintWriter(clientSocket.getOutputStream());

in = new InputStreamReader(clientSocket.getInputStream());

data = new BufferedReader(in);

data.read(cbuff, 0, 80);

lblResult.setText(String.copyValueOf(cbuff) + '\n');

//clean up

out.close();

in.close();

data.close();

clientSocket.close();

}

catch(UnknownHostException e)

{

lblResult.setText("Unknown host: "+ e.getMessage());

}

catch(IOException ioe)

{

lblResult.setText("IO Error "+ ioe.getMessage());

}

setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

The example is from a client we did last semester for a random quote of the day server/client.

Thanks,

Jason

[1460 byte] By [CaffeinatedCoder] at [2007-9-30 17:48:06]
# 1
Please read the documents that define FTP first--you are not prompted for a username, you must use the "USER" command. http://www.faqs.org/rfcs/ftp-rfcs.htmlespecially http://www.faqs.org/rfcs/rfc959.html
jsalonen at 2007-7-6 14:18:56 > top of Java-index,Administration Tools,Sun Connection...
# 2
Does everything look OK though regarding the datastream? Did I handle it correctly?
CaffeinatedCoder at 2007-7-6 14:18:56 > top of Java-index,Administration Tools,Sun Connection...
# 3

I suppose so, but since the protocol is based on reading and writing lines I think you should rather use the readLine method, it'll make parsing the replies easier. And when writing commands to the server you should remember that the character encoding and line separator as defined by the protocol are ASCII and \r\n, Java tends to use the platform defaults which can be different. The easiest way to guarantee you'll use \r\n is creating a subclass for PrintWriter that uses the ASCII encoding and override the println method to print \r\n...

jsalonen at 2007-7-6 14:18:56 > top of Java-index,Administration Tools,Sun Connection...
# 4
I got the output to go kinda, I need a loop but I'm not sure what criteria to use. I tried while(bufferedreader.ready() == true)But that doesnt work either.
CaffeinatedCoder at 2007-7-6 14:18:56 > top of Java-index,Administration Tools,Sun Connection...
# 5

The condition is given in section 4.2 Ftp Replies of RFC 959, linked above.

In short, the replies are usually one line long, except when a hyphen follows the numeric reply code. The last line of a multi-line reply is a line that starts with the same numeric reply code followed by space. Please see the RFC for more details.

jsalonen at 2007-7-6 14:18:56 > top of Java-index,Administration Tools,Sun Connection...