ok, I got the progress of file downloading.
1)   I create  two new class   MyFileSystemView and MyFtpFile

public class MyFtpFile extends NativeFtpFile {
    private CountingInputStream InputCount = null;
    private CountingOutputStream OutputCount = null;


    protected MyFtpFile (final String fileName, final File file, final User
user) {
        super(fileName,file,user);
    }

    @Override
    public OutputStream createOutputStream(long offset) throws IOException {
        OutputStream outputs = super.createOutputStream(offset);
        OutputCount = new CountingOutputStream(outputs);
        return outputs;
    }

    @Override
    public InputStream createInputStream(long offset) throws IOException {
        InputStream ins = super.createInputStream(offset);
        InputCount = new CountingInputStream(ins);
        return new SwappedDataInputStream(InputCount);
    }

    public CountingInputStream getInputCount() {
        return InputCount;
    }

    public CountingOutputStream getOutputCount() {
        return OutputCount;
    }
}


public class MyFileSystemView implements FileSystemView {
  ....
  ....
  @Override
    public FtpFile getFile(String file) {

        // get actual file object
        String physicalName = SeedFtpFile.getPhysicalName(rootDir,
                currDir, file, caseInsensitive);
        File fileObj = new File(physicalName);

        // strip the root directory and return
        String userFileName = physicalName.substring(rootDir.length() - 1);
        MyFtpFile ftpfile = new MyFtpFile (userFileName, fileObj, user);
        if (userFtpManager != null) {                          // the
userFtpManager is my own object for to mamanger the ftpfile object
            userFtpManager.setFtpFile(user, ftpfile);    //to save the new
ftpfile
        }
        return  ftpfile;
    }
.....
.....
}


2) inject it into the ftpserver
        m_FtpServerFactory = new FtpServerFactory();
        m_FtpServerFactory.setFileSystem(new MyFileSystemFactory());

3)  to get progress for file downloading
userFtpManager.getDownloadPercent(User user) {
            if (CurrFtpFile != null) {
                CountingInputStream count = CurrFtpFile.getInputCount();
                if (count != null) {
                    double totalSize = CurrFtpFile.getSize();
                    int percent = (int) (((double)(count.getByteCount()) /
totalSize) * 100L);
                    System.out.println(String.format("User:%s File:%s read
%d-%d percent:%d ", TerminalCode, CurrFtpFile.getName(),
count.getByteCount(), count.getCount(),percent));
                    return percent;
                }
            }
            return 0;
        }


thank sam


2013/6/19 Nick Yang <yr.n...@gmail.com>

> thank sam, I try to do it now!
>
>
> 2013/6/19 Sam Mizanin <sammyuglykid...@yahoo.com>
>
>> You need to have your own FileSystemView and FtpFile. In the FtpFile,
>> there are two methods createInputStream and createOutputStream. Pass your
>> own child class for inputstream and outputstream, override read and write
>> respectively and accordingly show your progress.
>>
>>
>> ________________________________
>>  From: Nick Yang <yr.n...@gmail.com>
>> To: ftpserver-users@mina.apache.org
>> Sent: Wednesday, 19 June 2013, 19:55
>> Subject: Re: how can get file downloading progress?
>>
>>
>> thank you! I have been defined a ftplet class for myself already, but the
>> onDownloadEnd and onDownloadStart function can not get downloading
>> progress.  My mean  is to get a percent of the file downloading from
>> server. how do to it?
>>
>>
>> 2013/6/19 John Hartnup <john.hart...@gmail.com>
>>
>> > Look at the ftplet interface.
>> > https://cwiki.apache.org/FTPSERVER/ftplet.html
>> >
>> > Specifically the onDownloadEnd() method.
>> >
>> >
>> > On 19 June 2013 12:02, Nick Yang <yr.n...@gmail.com> wrote:
>> >
>> > > hello everyone, I want to design a monitor for the ftpserver. How can
>> i
>> > get
>> > > the downloading progress when the client download file from ftpserver?
>> > >
>> >
>> >
>> >
>> > --
>> > "There is no way to peace; peace is the way"
>> >
>>
>
>

Reply via email to