Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Download all files from a folder on server

Tags:

android

Hope I am able to explain this correctly... I am able to connect to my web server and download a single file.What I am now attempting to do is connect to my server and download all the flies from a particular folder.In this case i want to download images. This is the code i use to download a single file...

URL url  = new URL("http://127.0.0.1/Folder/file.csv");
            URLConnection conexion = url.openConnection();
            conexion.connect();
            int lenghtOfFile = conexion.getContentLength();
            InputStream is = url.openStream();
            File testDirectory = 
            new File(Environment.getExternalStorageDirectory()+"/Folder");
            if(!testDirectory.exists()){
                testDirectory.mkdir();
            }
            FileOutputStream fos = new FileOutputStream(testDirectory+"/file.csv");
            byte data[] = new byte[1024];
            int count = 0;
            long total = 0;
            int progress = 0;
            while ((count=is.read(data)) != -1){
                total += count;
                int progress_temp = (int)total*100/lenghtOfFile;
                if(progress_temp%10 == 0 && progress != progress_temp){
                    progress = progress_temp;
                }
                fos.write(data, 0, count);
            }
            is.close();
            fos.close();

How can I add to this code to make it download all the files from that folder?

like image 488
Beginner Avatar asked Feb 17 '11 10:02

Beginner


1 Answers

I would suggest you to have a script at server's end, which first gives you list of all the files inside a folder, and then your application downloads each file one by one.

like image 153
Aman Alam Avatar answered Oct 16 '22 20:10

Aman Alam