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

K

KGuru

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!
 
T

Thomas Weidenfeller

KGuru said:
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
 
K

KGuru

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
 
K

KGuru

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
 
T

Thomas Weidenfeller

KGuru said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top