Jakarta common/net FTP - setRestartOffset - Upload Resume...

Discussion in 'Java' started by KGuru, Mar 22, 2006.

  1. KGuru

    KGuru Guest

    Hi all,

    I have tried to understand how to resume an upload or download using
    the FTPClient API from Jakarta common net libraries.

    1- I started by uploading a file on the FTP server then I interupted
    the upload in the middle (after for example 790000 bytes) :

    FTPClient ftp=new FTPClient();
    ....
    input = new FileInputStream("fileSourceName");
    output = ftp.storeFileStream("fileTargetName");
    ....
    Util.copyStream(input, output);

    2- I restart the program but I have added a line of code that describe
    an offset:

    FTPClient ftp=new FTPClient();
    ftp.setRestartOffset(790000);

    3- I was expecting that the download will restart from the offset
    instead the file upload starts from beginning...

    a- In fact i checked the Util.copystream method, i cannot see any use
    of the offset or is it simply handled by the FTP server?

    b-I'm just wonderinfg thatif it is handled by the FTP server,
    how does the FTP server knows where to start etc.. if the connection is
    restarted...

    c-if anyone has succesfully written the code that handles the "resume"
    functionnality, it would be nice to see some code snippet.

    Many Thanks!
     
    KGuru, Mar 22, 2006
    #1
    1. Advertising

  2. KGuru wrote:
    > a- In fact i checked the Util.copystream method, i cannot see any use
    > of the offset or is it simply handled by the FTP server?
    >
    > b-I'm just wonderinfg thatif it is handled by the FTP server,
    > how does the FTP server knows where to start etc.. if the connection is
    > restarted...
    >
    > c-if anyone has succesfully written the code that handles the "resume"
    > functionnality, it would be nice to see some code snippet.


    Like always in such cases (maybe we should make a
    mini-networking-debugging-FAQ out of this):

    1) Sniff the network with a tool like Ethereal, snoop, or whatever to
    see what is really going on on the network

    2) Check the documentation of the server if and how it supports resuming
    some transfer, and with which protocol (part).

    3) Get a copy of the relevant RFC(s) to check if and how the protocol
    should work and is actually used.

    /Thomas
    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Mar 22, 2006
    #2
    1. Advertising

  3. KGuru

    KGuru Guest

    Thanks fo your answer,

    I was doing all the research and debug you are mentionning. I'm just
    looking for someone who had experience the same type of problems and
    how it was solved.

    One discovery I made was that the FTP server was not supporting FTP
    command such as : REST and SIZE command send by the API in order to
    resume the upload.

    Best regards
    KGuru
     
    KGuru, Mar 23, 2006
    #3
  4. KGuru

    KGuru Guest

    I think there is a bug in the common-net FTP Jakarta component, in the
    Util package.


    by adding the following line of code in the Util package in the
    copyStream method:
    try {
    ----->>> source.skip(offset); <<<<-----
    while ((bytes = source.read(buffer)) != -1) {

    the offset represents the size of the file on the server which is
    returned by the following code (as i can't find the fileSize
    method...): ftpfiles is returned by
    ftp.initiateListParsing().getFiles().

    for(int i=0; i<ftpFiles.length;i++){
    if (ftpFiles.getName().equalsIgnoreCase(filename)){
    return ftpFiles.getSize();
    }
    }

    of course there was a need to set at the beginning og the code:
    ftp.setRestartOffset(offset);


    I'm not sure i'm clear ;> but I hope one has understood the logic. Is
    there any better idea???

    Br,
    KGuru
     
    KGuru, Mar 23, 2006
    #4
  5. KGuru wrote:
    > I was doing all the research and debug you are mentionning.


    How should we know if you don't mention this in your first post?

    > One discovery I made was that the FTP server was not supporting FTP
    > command such as : REST and SIZE command send by the API in order to
    > resume the upload.


    So you know your answer: Use another FTP server.

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Mar 23, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Barry
    Replies:
    1
    Views:
    2,558
  2. ht6554
    Replies:
    0
    Views:
    2,252
    ht6554
    Apr 6, 2006
  3. Replies:
    2
    Views:
    823
    Oliver Wong
    Jul 28, 2006
  4. untung
    Replies:
    0
    Views:
    449
    untung
    Oct 7, 2009
  5. D. Buck
    Replies:
    2
    Views:
    492
    D. Buck
    Jun 29, 2004
Loading...

Share This Page