Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
KGuru - 22 Mar 2006 08:55 GMT
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!
Thomas Weidenfeller - 22 Mar 2006 09:32 GMT
> 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?
[quoted text clipped - 5 lines]
> 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
Signature

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/

KGuru - 23 Mar 2006 08:23 GMT
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 - 23 Mar 2006 10:43 GMT
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[i].getName().equalsIgnoreCase(filename)){
                return ftpFiles[i].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
Thomas Weidenfeller - 23 Mar 2006 12:23 GMT
> 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

Signature

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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.