简体   繁体   English

使用Java 6编写FTP客户端

[英]Write FTP client with Java 6

I want to write a small project for myself - FTP client. 我想为自己编写一个小项目-FTP客户端。 I know to work with GUI, Socket & ServerSocket for TCP communication. 我知道可以使用GUI,Socket和ServerSocket进行TCP通信。 I ask you to tell me what I need more to know for implemening FTP client... Thanks 我想请您告诉我实现FTP客户端需要更多的知识...谢谢

First, you need to read the RFC. 首先,您需要阅读RFC。 After implementing the most common operations, test your client with at least one good FTP servers. 实施最常见的操作后,请至少使用一台良好的FTP服务器测试您的客户端。 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 . 前一段时间,我为H2数据库项目编写了一个FTP客户端

There's a fair amount built into standard Java (note, not JAVA, it's not an acronym). 标准Java内置了很多功能(请注意,不是JAVA,不是首字母缩写)。

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, ie Apache Commons Net . 您可能想知道存在一些库,例如Apache Commons Net Apart from that you might want to look at NIO for some novel approach to network communication. 除此之外,您可能还想看一下NIO,了解一些新颖的网络通信方法。 Not saying anything about character encodings (for ASCII transfer you might need it), called Charset incorrectly. 没有说任何关于字符编码的信息(对于ASCII传输,您可能需要使用它),这称为Charset错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM