Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
10.2k views
in General by (440 points)
Hello,

I am checking out the edtftpj API and I have tossed together a quick little program to download a jar file and use FTPProgressMonitor to show the chunks as they come down.

Is there some way to use the FTPProgressMonitor to calculate the percent downloaded?

Thanks,
steve

6 Answers

0 votes
by
The progress monitor reports the bytes downloaded. If you use size() (and it works on your FTP server) to find the total size of the file you are downloading beforehand, you can then work out the percentage downloaded.

Hello,

I am checking out the edtftpj API and I have tossed together a quick little program to download a jar file and use FTPProgressMonitor to show the chunks as they come down.

Is there some way to use the FTPProgressMonitor to calculate the percent downloaded?

Thanks,
steve
0 votes
by (440 points)
How would I go about passing the size into the monitor?
0 votes
by
To use the progress monitor, you need to implement FTPProgressMonitor in a class of your own, e.g. MyFTPProgressMonitor.

Get the size, and then pass it into MyFTPProgressMonitor via the constructor, e.g.

FTPProgressMonitor monitor = new MyFTPProgressMonitor(size);

Call ftp.setProgressMonitor (monitor, interval) to set it up before you do the transfer.

When the bytesTransferred(long count) method is called by the FTPClient, you can work out the percentage transferred each time.

How would I go about passing the size into the monitor?
0 votes
by (440 points)
:wink:

Thank you very much!
0 votes
by
how can i catch the parameter then?? i dont know how to do it this way?!
could you give me perhaps a code example..!?

thanks!
0 votes
by (440 points)
Here is the code from the main program. This creates the progress monitor and passes in the complete size

// MySize was defined earlier as a long int.
MySize = ftp.size(targetFile);
//here a new ftpprogressmonitor is created from the classfile
// ProgressMonitor.class (which appears below...)
FTPProgressMonitor monitor = new ProgressMonitor();
// In the Progress Monitor class is the MyNum variable. we set it here.
ProgressMonitor.MyNum = MySize;
//Monitor is setup.
ftp.setProgressMonitor(monitor, 1024);
// Transfer type is set.
ftp.setType(FTPTransferType.BINARY);
// Download the file
ftp.get(tmpOutput, targetFile);

-------------------------------
This is the complete ProgressMonitor.java Classfile.
-------------------------------
import com.enterprisedt.net.ftp.*;

public class ProgressMonitor implements FTPProgressMonitor {
public static long MyNum = 0;

public void bytesTransferred(long count) {
float answer = ( ( (int)count / (int)MyNum )+1 );
System.out.println(count + " : " + answer );
}
}

Hope this helps. If you need the complete code for the main program, let me know.

Categories

...