tags:

views:

77

answers:

3

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.openInputStream() );
            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.

+1  A: 

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

Catalin DICU
A: 

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

nos
A: 

I wrote a pretty easy to use wrapper library for all the FtpWebRequest stuff. If you care to check it out, it's here http://bit.ly/3IL4kW

I use it in a lot of production environments and it hasn't failed me yet.

Jason Kostempski