2009-11-16 50 views
0

我正在構建一個應用程序,該應用程序向遠程FTP服務器發送/接收大量數據。我想通過SocketConnection實現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()); 
     } 
    } 
} 

我需要從專家的建議/建議如何執行此操作。

回答

0

您確定需要構建自己的FTP客戶端嗎?檢出FtpWebRequest,.NET的一部分

相關問題