Anyway, I remembered that there was an RFC on FTP. A little bit of googling got me the paper that I wanted, RFC 959. To be honest, it wasn't as simple as I would expect it to be. That didn't stop me from starting coding. The first thing that came to my mind was to create a Socket to an FTP server on port 21 and start sending FTP commands.
Socket ftpclient = new Socket("ftp.someserver.com", 21);
InputStream is = ftpclient.getInputStream();
do {
byte[] b = new byte[1024];
int len = is.read(b);
System.out.println(new String(b, 0, len));
} while (is.available() > 0);
Next, I tried logging in. I quickly found out that you had to end each command with CRLF (\r\n).
OutputStream os = ftpclient.getOutputStream();
os.write("USER anonymous\r\n".getBytes());
// readInputStream . . .
os.write("PASS guest\r\n".getBytes());
// readInputStream . . .
os.write("QUIT\r\n".getBytes());
// readInputStream . . .
No comments:
Post a Comment