PDA

View Full Version : QFTP resume download



wagui
10th March 2008, 14:28
Hello,

I'm working with QFtp and I have to implement a function that can allow user to resume an aborted download. I found the REST command from FTP RFC. I'm trying to use it with the "get" method but it doesn't work.

Do you have any idea ?

Here is my code :


ftp->connectToHost(url.host(), url.port(21));
ftp->login();
reqRange="rest "+"100"; //In order to restart after 100 bytes, reqRange is a static buffer
ftp->rawCommand(reqRange); //Without that line at the beginning, the download starts
ftp->get(url.path(),file);

Thank you,

Wagui

wysota
11th March 2008, 12:35
I think you have to send "RETR" command instead of using QFtp::get().

wagui
11th March 2008, 13:07
Thanks for your help.

I have another questions : Do I have to use the passive mode (PASV command) ? Do you know if the get method send a PASV command behind ?

I don't find any example of transmission.

Thanks a lot !

Wagui

wysota
11th March 2008, 13:39
It's best to take a network sniffer and see for yourself. Probably it doesn't.

wagui
12th March 2008, 07:29
I used a network sniffer and found that the get method sends a PASV command. So the transfer uses the FTP DATA. But when i use the rawCommand("RETR file.txt") method how do you retrieve the file from the FTP DATA.

Thanks for your help.

Wagui

wysota
12th March 2008, 07:39
Probably using QFtp::read().

wagui
12th March 2008, 09:30
I tried to use QFtp::read() method but this doesn't work, here is my code :



ftp->rawCommand("TYPE I");
ftp->rawCommand("PASV");
reqRange="REST "+stailleEnreg;
ftp->rawCommand(reqRange);
reqRange="RETR "+url.path();
ftp->rawCommand(reqRange);

char*bytes;
bytes=(char*)malloc((tailleFichier-tailleEnreg+1)*sizeof(char));

ftp->read(bytes,tailleFichier-tailleEnreg);
file->write(bytes,tailleFichier-tailleEnreg); //tailleFichier-tailleEnreg is the size of the end of the file.

When i use ethereal to see what happened : after the RETR the server doesn't return any response, he would have sent "125 Transfer starting"

Thanks,

Wagui

wysota
12th March 2008, 09:54
It doesn't work like that. You can't read immediately as there is nothing to be read. If the server doesn't respond to your command it probably means the ftp protocol assumes some other behaviour.

wagui
12th March 2008, 10:47
I think i 've found where is the problem. It seems that the get method from QFtp uses PASV command then listen and wait for a connection from the server. Then the data are transferred on this connection. I don't do that, and i think it's the reason of this problem.

Perhabs some functions in the QtNetwork library can help me to do these low level operations.

Wagui

wagui
14th March 2008, 14:15
Hello,

I don't find any method to make a connection on the data ftp. With the sniffer, i can display that :

TYPE I
200 Type set to I
REST 471580
350 Restarting at 471580
PASV
227 Entering Passive Mode (193,49,90,3,10,235);
RETR /dossier/fichier.avi
425 Can't open data connection

Perhabs it's because i don't listen on a port on my computer. I didn't find any method to do that. Have you any idea about the problem ? Perhabs i forgot something important ...


Thanks a lot

Wagui