Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7029343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:31:36+00:00 2026-05-28T00:31:36+00:00

I have a working FTP system with android, but I want to be able

  • 0

I have a working FTP system with android, but I want to be able to track the bytes as they get uploaded, so I can update a progress bar as the upload progresses. Is this possible with Android? Right now, I’m using org.apache.common.net.ftp and the code I’m using is below. Also, I am running this in an AsyncTask.

package com.dronnoc.ftp.complex;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketException;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.io.CopyStreamEvent;
import org.apache.commons.net.io.CopyStreamListener;
import org.apache.commons.net.io.Util;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

public class Main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);


        setContentView(R.layout.main);

        String text = "BIGFILE"; //Big file here

        InputStream data = new ByteArrayInputStream(text.getBytes());

        new ComplexFTPTransfer().execute(data);
    }

    private class ComplexFTPTransfer extends AsyncTask<InputStream, Long[], Void>
    {
        private FTPClient ftp = null;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            try {
                ftp = new FTPClient();
                ftp.connect("hostname");
            } catch (SocketException e) {
                this.cancel(true);
            } catch (IOException e) {
                this.cancel(true);
            }

            Main.this.setProgressBarIndeterminateVisibility(true);

        }


        @Override
        protected Void doInBackground(InputStream... params) {
            if(!this.isCancelled())
            {
                try 
                {
                    if(ftp.login("user", "pass"))
                    {
                        ftp.enterLocalPassiveMode();

                        InputStream item = params[0];

                        int streamSize = 0;
                        while(item.read() != -1)
                        {
                            streamSize++;
                        }

                        InputStream is = new BufferedInputStream(params[0], streamSize);
                        OutputStream os = ftp.storeFileStream("/test.txt");

                        Util.copyStream(is, os, streamSize, streamSize, new CopyStreamListener() {

                            @Override
                            public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {
                                publishProgress(new Long[] {totalBytesTransferred, streamSize});
                            }

                            @Override
                            public void bytesTransferred(CopyStreamEvent event) {

                            }
                        });
                        ftp.completePendingCommand();
                    }
                    ftp.logout();
                    ftp.disconnect();

                }
                catch (IOException e) {

                }
                catch (Exception e) {

                }
            }
            return null;
        }


        @Override
        protected void onProgressUpdate(Long[]... values) {
            super.onProgressUpdate(values);
            Log.d("UPDATE", values[0] + " of " + values[1] + " copied.");
            //TODO Put code here
        }

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            Main.this.setProgressBarIndeterminateVisibility(false);
        }
    }
}

What I want to know is if I can run a progress bar, updating every few uploaded bytes?
Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:31:36+00:00Added an answer on May 28, 2026 at 12:31 am

    This question has an implementation of an InputStream that includes a progress callback. Use that InputStream and call publishProgress from that callback for incremental updates during the file upload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have tried using ant ftp tasks, but could not get it working like
I have a simple put and get working, but can't seem to find how
I have a working LINQ to SQL model. I want to be able to
I have this working definition: IDENTIFIER [a-zA-Z][a-zA-Z0-9]* I don't want to keep repeating the
I have been working with relational databases for sometime, but it only recently occurred
I have WAMP 2.0 installed and am working on a content management system using
currently I'm working on this ftp transfer. http://msdn.microsoft.com/en-us/library/ms229715.aspx I have setup my server computers
I am trying to get http://www.emacswiki.org/emacs/PrettyGreek working for emacs 21.3.1 on Windows. I have
im working on a content management system for that i have to download a
I want to use the FTP task in ant, and I have found the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.