【问题标题】:How can I talk to FTP server by implementing commands over SocketConnection如何通过 SocketConnection 实现命令与 FTP 服务器通信
【发布时间】:2009-11-16 10:50:17
【问题描述】:

我正在构建一个应用程序,用于向/从我的远程 FTP 服务器发送/接收大数据。我想通过 SocketConnection 实现 FTP 命令。在验证所需的响应后,我必须先打开连接,然后打开用户密码,然后才能开始下载/上传。我知道如何开始。我只有一个想法:

public class SimpleFTP
{

    private static boolean DEBUG = false;
    StreamConnectionNotifier connectionNofitier = null;
    InputStreamReader reader = null;
    OutputStreamWriter writer = null;
    StreamConnection conn = null;
    private static String URL = null;
    private String server = "XXX.XXX.XXX.XX";
    private String port = "21";
    private String user = "user";
    private String pwd = "pwd";


    public SimpleFTP()
    {
    }


    public void connect() throws IOException
    {


        try
        {
            URL = "socket://" + server + port + user + pwd+";deviceside=true";
            URL = "socket://" + server + port +";deviceside=true";
            connectionNofitier = (StreamConnectionNotifier) Connector.open(URL); 
            System.out.println(Connector.open(URL));

            if(connectionNofitier!=null)
                System.out.println("StreamConnectionNotifier is already connected..!!");

            conn = (StreamConnection)connectionNofitier.acceptAndOpen(); ;

            if(conn!=null)             //my Simulator hangs here and does nothing....
                System.out.println("StreamConnection is already connected..!!");

            reader = new InputStreamReader( conn.openInputStream() );
            writer = new OutputStreamWriter( conn.openOutputStream() )  ;
        }
        catch(Exception e )
        {
            System.out.println("Exception in Connect : "+e.toString() );
        }
    }
}

我需要专家关于如何执行此操作的建议/建议。

【问题讨论】:

    标签: .net ftp sockets


    【解决方案1】:

    FTP 协议 (http://www.ietf.org/rfc/rfc959.txt) 比 HTTP 或 Telnet 形式的示例更复杂。您应该使用现有的 FTP 库:http://www.google.fr/search?q=.net+ftp+library

    【讨论】:

      【解决方案2】:

      您确定需要构建自己的 FTP 客户端吗?查看FtpWebRequest,.NET 的一部分

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        • 2011-09-23
        • 2021-12-29
        • 1970-01-01
        • 1970-01-01
        • 2011-06-09
        • 1970-01-01
        相关资源
        最近更新 更多