Write FTP client with Java 6
I want to write a small project for myself - FTP client. I know开发者_运维技巧 to work with GUI, Socket & ServerSocket for TCP communication. I ask you to tell me what I need more to know for implemening FTP client... Thanks
First, you need to read the RFC. After implementing the most common operations, test your client with at least one good FTP servers. There are a few things in the spec that are easy to get wrong. Then, compare what you wrote with other implementations. Some time ago, I wrote an FTP client for my H2 Database project.
There's a fair amount built into standard Java (note, not JAVA, it's not an acronym).
It could be this simple
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
// ....
try {
URL url = new URL("ftp://user:pwd@ftp.example.com/test.txt;type=i");
URLConnection connection = url.openConnection();
InputStream inputStream = connection.getInputStream();
OutputStream outputStream = connection.getOutputStream();
// ... do something useful
} catch (IOException ex) {
// report the error
}
You might want to know that some libraries exist, i.e. Apache Commons Net. Apart from that you might want to look at NIO for some novel approach to network communication. Not saying anything about character encodings (for ASCII transfer you might need it), called Charset incorrectly.
精彩评论