Question

iam trying to upload file(small and large) to my server via ftp.

the uploading part of ftp is working fine.

Now i require.. 1) progressDialog showing the transferred(uploaded) data. 2) if possible the ETA time to be displayed along.

posting what i have done so far.

private class uploadFileTask extends AsyncTask<String, Integer, Long> {

    //void FTP_DATA_UPLOAD(String FULL_PATH_TO_LOCAL_FILE)
    private ProgressDialog progressDialog;
    int progressInput = 0;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setTitle("Upload file");
        progressDialog.setMessage("Sending file please wait...");
        progressDialog.setCancelable(false);
        progressDialog.setIndeterminate(false);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setProgress(0);
        progressDialog.setMax((int)uploadFilePath1.length());
        progressDialog.incrementProgressBy((int)((progressInput*100)/(uploadFilePath1.length())));
        progressDialog.show();
    }

    protected Long doInBackground(String... FULL_PATH_TO_LOCAL_FILE ) {
        // encapsulate FTP inside a A sync task

        {
            System.out.println("Entered FTP transfer function");

            FTPClient ftpClient = new FTPClient();
            int reply;
            try {
                System.out.println("Entered Data Upload loop!");
                ftpClient.connect("103.27.**.***",21);
                ftpClient.login("send", "gelvin");
                //ftpClient.changeWorkingDirectory("/directory/");
                System.out.println("Entered Data Upload loop!");


                int reply1 = ftpClient.getReplyCode();


                if(FTPReply.isPositiveCompletion(reply1)){
                    System.out.println("Connected Success");
                }else {
                    System.out.println("Connection Failed");
                    ftpClient.disconnect();
                }




                ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
                BufferedInputStream buffIn = null;
                System.out.println("Created an input stream buffer");
                System.out.println(FULL_PATH_TO_LOCAL_FILE.toString());

                buffIn = new BufferedInputStream(new FileInputStream(uploadFilePath1));
                ftpClient.enterLocalPassiveMode();

                System.out.println("Entered binary and passive modes");
                // Handler progressHandler=null;
                //ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);

                result = ftpClient.storeFile(uploadFileName, buffIn);



                //boolean result = ftpClient.storeFile(uploadFileName, buffIn); //localAsset.getFileName()
                //ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);

                if (result){
                    System.out.println("Success");
                }

                //boolean result = ftpClient.storeFile("TEST.jpg", progressInput);
                System.out.println("File saved");


                buffIn.close();
                ftpClient.logout();
                ftpClient.disconnect();


            } catch (SocketException e) {
                Log.e("SocketException", e.getStackTrace().toString());
                System.out.println("Socket Exception!");
            } catch (UnknownHostException e) {
                Log.e("UnknownHostException", e.getStackTrace().toString());
            } catch (IOException e) {
                Log.e("IOException", e.getStackTrace().toString());
                System.out.println("IO Exception!");
            }

            return null;
        }


    } 
    @Override
    protected void onProgressUpdate(Integer... progress)   {        
        super.onProgressUpdate(progress);
        progressDialog.setProgress(progress[0]); 
    } 



    @Override
    protected void onPostExecute(Long result) {  
        progressDialog.dismiss();
    }
}

please help me with this

No correct solution

OTHER TIPS

you can customize your dialog, for that you can refer below link

http://custom-android-dn.blogspot.in/2013/01/how-to-create-custom-progress-bar-and.html

Android change Horizonal Progress bar color

I think it may be help you.

Here is complete code of custome class,

http://www.learn-android-easily.com/2013/05/custom-progress-bar-in-android.html

You have to just open that dialog in preExecute method of Async task and close it into postExecute method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top