开发者

How can I talk to FTP server by implementing commands over SocketConnection

I am building an app which sends/recv large data to/from my remote FTP server. I want to implement FTP commands over SocketConnection. I have to first open the connection and then user and then password to server, after verifying the required response I want to begin download/upload. I dn know how to begin. I have only idea :

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.openInput开发者_C百科Stream() );
            writer = new OutputStreamWriter( conn.openOutputStream() )  ;
        }
        catch(Exception e )
        {
            System.out.println("Exception in Connect : "+e.toString() );
        }
    }
}

I need suggestions/advice from experts to how to perform this.


FTP protocol (http://www.ietf.org/rfc/rfc959.txt) is more complex than HTTP or Telnet form example. You should use an existent FTP library : http://www.google.fr/search?q=.net+ftp+library


Are you sure you need to build your own FTP client ? Check out FtpWebRequest , part of .NET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜