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

  • Home
  • SEARCH
  • 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 8455213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:13:40+00:00 2026-06-10T12:13:40+00:00

OK so I have the uploader uploading files using the Java FTP, I would

  • 0

OK so I have the uploader uploading files using the Java FTP, I would like to update the label and the progress bar. Label with the percent text, bar with the percent int value. Right now with the current code only get the 100 and full bar at the end of the upload. During the upload none of them change.

here it is:

    OutputStream output = new BufferedOutputStream(ftpOut);
    CopyStreamListener listener = new CopyStreamListener() {
        public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {
            System.out.printf("\r%-30S: %d / %d", "Sent", totalBytesTransferred, streamSize);
            ftpup.this.upd(totalBytesTransferred,streamSize);
        }
        public void bytesTransferred(CopyStreamEvent arg0) { }
    };

    Util.copyStream(input, output, ftp.getBufferSize(), f.length(), listener);      
}

public void upd(long num, long size){
    int k = (int) ((num*100)/size);
    System.out.println(String.valueOf(k));
    this.d.setText(String.valueOf(k));
    //d.setText(String.valueOf(k));
    progressBar.setValue(k);
}
  • 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-06-10T12:13:41+00:00Added an answer on June 10, 2026 at 12:13 pm

    From the sounds of it (and lacking any evidence to the contree) it sounds like your processing a time consuming action in the Event Dispatching Thread

    You might like to read Concurrency in Swing for some further insight

    I’d suggest using a SwingWorker to perform the actual transfer & take advantage of its built in progress support

    UPDATE after seeing source code

    1. Don’t mix heavy weight components with light weight components. Change Applet to JApplet, change TextField to JTextField, don’t use Canvas use a JPanel or JComponent
    2. If you expect other people to read your code, please use proper names for your variables, I have no idea what p is.
    3. Your Thread is useless. Rather then starting the thread and using it’s run method you simply make your download call within it’s constructor. This will do nothing for you…

    Remove your implementation of MyThread and replace it with

    public class MyWorker extends SwingWorker<Object, Object> {
    
        private URL host;
        private File outputFile;
    
        public MyWorker(URL host, File f) {
            this.host = host;
            outputFile = f;
        }
    
        @Override
        protected Object doInBackground() throws Exception {
    
            // You're ignoring the host you past in to the constructor
            String hostName = "localhost";
            String username = "un";
            String password = "pass";
            String location = f.toString();
    
            //FTPClient ftp = null;
    
            ftp.connect(hostName, 2121);
            ftp.login(username, password);
    
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
    
            ftp.setKeepAlive(true);
            ftp.setControlKeepAliveTimeout(3000);
            ftp.setDataTimeout(3000); // 100 minutes
            ftp.setConnectTimeout(3000); // 100 minutes
    
            ftp.changeWorkingDirectory("/SSL");
    
            int reply = ftp.getReplyCode();
            System.out.println("Received Reply from FTP Connection:" + reply);
    
            if (FTPReply.isPositiveCompletion(reply)) {
                System.out.println("Connected Success");
            }
            System.out.println(f.getName().toString());
    
            File f1 = new File(location);
            in = new FileInputStream(f1);
    
            FileInputStream input = new FileInputStream(f1);
            // ftp.storeFile(f.getName().toString(),in);
    
            //ProgressMonitorInputStream is= new ProgressMonitorInputStream(getParent(), "st", in);
            OutputStream ftpOut = ftp.storeFileStream(f.getName().toString());
    
    
            System.out.println(ftpOut.toString());
            //newname hereSystem.out.println(ftp.remoteRetrieve(f.toString()));
            OutputStream output = new BufferedOutputStream(ftpOut);
            CopyStreamListener listener = new CopyStreamListener() {
                public void bytesTransferred(final long totalBytesTransferred, final int bytesTransferred, final long streamSize) {
    
                    setProgress((int) Math.round(((double) totalBytesTransferred / (double) streamSize) * 100d));
    
                }
    
                @Override
                public void bytesTransferred(CopyStreamEvent arg0) {
                    // TODO Auto-generated method stub
                }
            };
    
            Util.copyStream(input, output, ftp.getBufferSize(), f.length(), listener);
    
            return null;
    
        }
    }
    

    In your ActionListener of o (??) replace the thread execution code with

    try {
        MyWorker worker = new MyWorker(new URL("http://localhost"), file);
        worker.addPropertyChangeListener(new PropertyChangeListener() {
    
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("progress")) {
                    Integer progress = (Integer) evt.getNewValue();
                    progressBar.setValue(progress);
                }
            }
        });
        worker.execute();
    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    }
    

    Note. You are ignoring the URL you pass to the constructor. http:// is not ftp:// so I doubt this will work…

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

Sidebar

Related Questions

I have read the following tutorial Uploading Files To the Server Using PHP and
I have been using Indy to transfers files via FTP for years now but
How to go about uploading Multiple files(i have multiple files inside a folder) using
I have found this great tutorial, about uploading files with a Flex app, using
I have written a simple ftp uploader in C++ with qt using QNetworkAccessManager's put
I now have a file uploader that goes on like this This is the
I have a problem with dojox.form.Uploader. I want to use it to attach files
I have a function like this in actionscript3 private function uploadFile(event:MouseEvent):void { var uploader:URLRequest
I am currently uploading files in ActionScript 3 using the upload() method of the
I am using Cakephp as my framework. I have a problem in uploading my

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.