2013-05-02 16 views
0

我有存儲在http://user.mysite.com/content
文件現在我想在我的Android應用程序,實現了Web服務器,下載的每個文件的用戶可以上傳此服務器上,我已經創造了Android的功能,可以下載文件,並將其存儲到SD卡是這樣的:從服務器獲取的文件列表以及通話清單上下載功能下載內容

public void doDownload(){ 
    try { 
     int count; 
     URL url = new URL("http://user.mysite.com/content"); 
     URLConnection connection = url.openConnection(); 
     connection.connect(); 
     int lengthOfFile = connection.getContentLength(); 
     long total = 0; 
     InputStream input = new BufferedInputStream(url.openStream()); 
     OutputStream output = new FileOutputStream(f); 
     byte data[] = new byte[1024]; 
     while ((count = input.read(data)) != -1) { 
      total += count; 
      publishProgress((int)(total/1024),lengthOfFile/1024); 
      output.write(data, 0, count); 
     } 
     output.flush(); 
     output.close(); 
     input.close(); 
    } 
    catch (Exception e) { 
     Log.e("Download Error: ", e.toString()); 
    } 
} 

我怎麼能retrive服務器和URL對這些文件+名的文件列表的文件並下載其中的每一個應用程序使用循環?

獲取文件的列表,我有一些事情榜單:

public List clientServerFileList(){ 
    URL url; 
    List serverDir = null; 

    try { 
     url = new URL("http://user.mysite.com/content/");   
     ApacheURLLister lister = new ApacheURLLister();   
     serverDir = lister.listAll(url); 
    } 
    catch (Exception e) { 
     e.printStackTrace(); 
     Log.e("ERROR ON GETTING FILE","Error is " +e); 
    } 
    System.out.println(serverDir); 
    return serverDir; 
} 

我的服務器是:阿帕奇/ 2.2.24(Unix的)了mod_ssl/2.2.24的OpenSSL/1.0.0-FIPS mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635服務器在user.mysite.com端口80

+0

括號的數量}在您的第一個代碼塊中似乎不匹配。修復這個和你的代碼縮進。 – timss 2013-05-02 02:13:54

回答

0
  1. 發送POST或GET請求到您的服務器。當您的服務器收到此請求時,請將JSON或XML響應給客戶端。
  2. 解析服務器對您的XML或JSON響應,獲取文件名和...,您可以將文件下載到文件列表中。
+0

那不是一個可能的選擇。我無法在服務器端做任何事情!我需要一些方法來獲取服務器上的所有文件列表。 – star18bit 2013-05-03 00:42:43