2013-10-29 3 views
0

FTP로 연결하여 파일 목록을 가져오고 싶습니다. 이 내 코드입니다 :ftp에서 파일 목록을 가져올 수 없습니다.

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


     task getson = new task(); 
     getson.execute(); 




    } 

    FTPClient client; 

    public FTPClient connectWithFTP() throws IOException{ 
     client = new FTPClient(); 
     try { 

      client.connect(server, 21); 
      System.out.println("status :: " + client.getReplyString()); 
      int reply = client.getReplyCode(); 
       if (!FTPReply.isPositiveCompletion(reply)) { 
        throw new Exception("Connect failed: " + client.getReplyString()); 
       } 
       try { 
        client.enterLocalPassiveMode(); 
        if (!client.setFileType(FTP.BINARY_FILE_TYPE)) { 
         Log.v(getClass().toString(), "Setting binary file type failed."); 
        } 
       } catch(Exception e) { 
        e.printStackTrace(); 
       } 
      checkFiles(client); 
     } catch (Exception e) { 
      System.out.println("status :: " + client.getReplyString()); 
     } 
      return client; 
    } 

    private class task extends AsyncTask <Void, Void, FTPClient> { 

     @Override 
     protected void onPreExecute() { 
      // Do stuff before the operation 
     } 


     @Override 
     protected FTPClient doInBackground(Void... params) { 
      FTPClient ftp = null; 
      try { 
       ftp = connectWithFTP(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
      return ftp; 
     } 
    } 

    public void disconnectWithFTP() throws IOException{ 
     client.logout(); 
     client.disconnect(); 
    } 

    private void checkFiles(FTPClient clients){ 
      try { 
       FTPFile[] ftpFiles = clients.listFiles(); 
       int length = ftpFiles.length; 
       for (int i = 0; i < length; i++) { 
       String name = ftpFiles[i].getName(); 
       Calendar date = ftpFiles[i].getTimestamp(); 
       Log.v("aasd", name+", "+date); 

       } 
      } catch(Exception e) { 
       e.printStackTrace(); 
      } 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 

연결 작업,하지만 난 파일 목록을 할 때 얻을 :

10-29 12:25:25.113: I/System.out(1980): status :: 220 (vsFTPd 2.2.2) 
10-29 12:25:25.542: V/class com.example.ftp.MainActivity(1980): Setting binary file type failed. 
10-29 12:25:36.332: W/System.err(1980): java.io.IOException: Unable to determine system type - response: 530 Please login with USER and PASS. 
10-29 12:25:36.343: W/System.err(1980):  at org.apache.commons.net.ftp.FTPClient.getSystemType(FTPClient.java:2721) 
10-29 12:25:36.347: W/System.err(1980):  at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3256) 
10-29 12:25:36.355: W/System.err(1980):  at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930) 
10-29 12:25:36.363: W/System.err(1980):  at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2977) 
10-29 12:25:36.371: W/System.err(1980):  at com.example.ftp.MainActivity.checkFiles(MainActivity.java:87) 
10-29 12:25:36.378: W/System.err(1980):  at com.example.ftp.MainActivity.connectWithFTP(MainActivity.java:53) 
10-29 12:25:36.382: W/System.err(1980):  at com.example.ftp.MainActivity$task.doInBackground(MainActivity.java:72) 
10-29 12:25:36.390: W/System.err(1980):  at com.example.ftp.MainActivity$task.doInBackground(MainActivity.java:1) 
10-29 12:25:36.398: W/System.err(1980):  at android.os.AsyncTask$2.call(AsyncTask.java:185) 
10-29 12:25:36.398: W/System.err(1980):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
10-29 12:25:36.398: W/System.err(1980):  at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
10-29 12:25:36.402: W/System.err(1980):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
10-29 12:25:36.402: W/System.err(1980):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
10-29 12:25:36.402: W/System.err(1980):  at java.lang.Thread.run(Thread.java:1019) 

이 serwer가 열려, 로그인 및 암호없이. 왜 파일 목록을 가져올 수 없습니까?

답변

1

내 문제가 해결되었습니다. 해결책 :

client.login("anonymous", "anonymous"); 
관련 문제