Get list of files from server and Call download function on that list to download content

I have a web server that stores the files at http://user.mysite.com/content Now all I want to achieve in my android application is to download every files that user can upload on this server, I have created function in android that can download files and stores it into sdcard which is something like this:

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());
    }
}

How can I retrive the list of files on server and URL for those files + name of files and download Each one of them on to app using loop?

To get the list of file I have some thing list this:

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;   
} 

My server is: Apache/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 Server at user.mysite.com Port 80

Answers


  1. Send a POST or GET request to your server. When your server recive this request, response the JSON or XML to the client.
  2. Parse the XML or JSON that server response to you, get the filename and ..., you can download the file in the file list.

Need Your Help

set scrollTop and scrollLeft without javascript

javascript css scrolltop

I have a question about the scrollTop and scrollLeft properties. I would like to set these properties in my div without using JavaScript (jquery). Is this possible?

ColdFusion Limit to 5 E-mails a Day

coldfusion cfmail

Say I have the following script on page.cfm. Everytime somebody comes to page.cfm, an e-mail is sent to me. So if 1000 people come to page.cfm, I get 1000 e-mails.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.