#### Archived

This topic is now archived and is closed to further replies.

This topic is 5326 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello... I have been working on a program which will find and download mshn files from FTP servers... I have all of the ftp stuff done... except for the code to allow resuming of files. Which is pretty much a must have because the average file size here is around 50megs... I am using WinInet functions due to them being the only library of function that supported multi-threading correctly, which is also a definate must have. Right now I have the following code: For some reason the InternetSetFilePointer function gets passed all of the correct information, but when I go to retrieve data, it starts from the beggening anyway... Does anyone know of how I can do this?
void Connection::DownloadPair(DLPair dlp)
{
//FtpGetFile(conn, dlp.remote.c_str(), dlp.local.c_str(), false, NULL, FTP_TRANSFER_TYPE_BINARY, (DWORD)&dlcbd);	// start the file transfer

HINTERNET dlfile = FtpOpenFile(conn, dlp.remote.c_str(), GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, (DWORD)&dlcbd);	// open the file

// I tried using this open function it didn''t retrieve any data at all...

//HINTERNET dlfile = InternetOpenUrl(conn, dlp.remote.c_str(), NULL, 0, INTERNET_FLAG_PASSIVE, (DWORD)&dlcbd);	// open the file

struct _stat fs;
FixDir(&dlp.local, ''\\'');
int res = _stat(dlp.local.c_str(), &fs);
if(!res)
{
if(fs.st_size >= dlp.size)																	// if the file that is already there is just as big or bigger that the one we are trying to download, we don''t do anything here

{
InternetCloseHandle(dlfile);
return;
}
LONG lsize = fs.st_size;
InternetSetFilePointer(dlfile, lsize, NULL, FILE_BEGIN, NULL);								// we should start here... not at the beggining

}
void *buffer = new char[buffersize];
FILE *local = NULL;
if(!(local = fopen(dlp.local.c_str(), "a")))
{
InternetCloseHandle(dlfile);
return;
}

do
{
//		fclose(local);

InternetCloseHandle(dlfile);
fclose(local);
}
the dlp structure holds a string specifing the local and remote files that we are dealing with along with the remote filesize. If anyone could help me out some, That would be great. Surely someone has gotten the WinInet API to resume an FTP download... Thanks Dwiel

##### Share on other sites
(Using the Microsoft protocol implementation?)

##### Share on other sites
I just used a different client to download/resume the same file, and it worked just fine. Maybe I should try doing this part manually... maybe I can send a REST xxx command right before I try downloading something. That seems like a bad solution though because it might not always work. hmm...

any more ideas...

Thanks!

Dwiel

##### Share on other sites
Incase anyone is interested or searching, I was finally able to do this by using the function FtpCommand and manually sending the "REST" command allong with the byte number I would like to resume from... ex: "REST 1024" to resume starting on the 1024th byte. You then must download the file using FtpOpenFile and InternetReadFile. The FtpCommand must come BEFORE the open file or the downloading will not work.

This caused me a huge headache and around 3 or 4 hours. I finally figured it out after corresponding with a helpful person named Narendra Chandel.

anyway, hopefully someone else can benifit from this being in an easy to find place

Dwiel

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5

• 21
• 19
• 11
• 13
• 17
• ### Forum Statistics

• Total Topics
631697
• Total Posts
3001764
×