Restart a download

This forum is not monitored by the SmartFTP staff. If you have a license please contact technical support by email.
Post Reply
donj91711
Posts: 33
Joined: Fri Jul 30, 2010 7:01 pm

Restart a download

Post by donj91711 » Tue Dec 21, 2010 12:06 am

Hello,

Sometimes I try to download a large file and it times out. Here is a section of the log:

[20101220 19:11:17] 257 "/ResultDocs" is your current location
[20101220 19:12:20] SIZE 2010-11-30.zip
[20101220 19:12:20] 213 900186896
[20101220 19:12:31] PASV
[20101220 19:12:31] 227 Entering Passive Mode (63,232,53,150,39,85)
[20101220 19:12:31] Opening data connection to 63.232.53.150 Port: 10069
[20101220 19:12:31] RETR 2010-11-30.zip
[20101220 19:12:31] 150-Accepted data connection
[20101220 19:12:31] 150 879088.8 kbytes to download
[20101220 21:37:45] Transfer Timeout (30s). Closing data connection.
[20101220 21:37:45] 888966400 bytes transferred. (99.6 KB/s) (02:25:13)
[20101220 21:38:15] Timeout (30s).
[20101220 21:38:15] 3
[20101220 21:38:15] Client closed the connection.
[20101220 22:42:59] SmartFTP FTP Library 2.0.86.0


My line of code that runs the download is:

ret = objFTP.DownloadFile(FileName, ResultDocPath & FileName, nRestartLo, nRestartHi)

The return value is 3

My question is, how do I try again/resume without restarting from the begining? I know it has something to do with the values nRestartLo and nRestartHi, but I can't find a peice of sample code on your web site that shows that. I'm sure this is a simple procedure. Can you please point me to a sample of this?

Thanks

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: Restart a download

Post by mb » Tue Dec 21, 2010 12:32 am

You need to get the file size of the remote file. Then, depending on your rules you are deciding whether you want to resume the existing file.
To get the file size use the Stat() function. In C++:

long nSFTPFlags = 0;

if(nFlags & sfTransferQueueConnectionGetFileItemSize)
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributeSize;

if(nFlags & sfTransferQueueConnectionGetFileItemModifyTime)
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributeModifyTime;

if(nFlags & sfTransferQueueConnectionGetFileItemCreateTime)
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributeCreateTime;

if(nFlags & sfTransferQueueConnectionGetFileItemAccessTime)
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributeAccessTime;

if (nFlags & sfTransferQueueConnectionGetFileItemPermissions)
{
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributePermissions;
// Request other attributes
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributeBits;
}

if (nFlags & (sfTransferQueueConnectionGetFileItemOwner | sfTransferQueueConnectionGetFileItemGroup))
nSFTPFlags |= sfFTPLib::ftpSFTPItemAttributeOwnerGroup;

sfFTPLib::enumError ret = m_pSFTPConnection->Stat(bstrPath, nSFTPFlags);
if(ret == sfFTPLib::ftpErrorSuccess)
{
sfFTPLib::ISFTPItemPtr pLastItem = m_pSFTPConnection->LastItem;
ATLENSURE(pLastItem);

donj91711
Posts: 33
Joined: Fri Jul 30, 2010 7:01 pm

Re: Restart a download

Post by donj91711 » Tue Dec 21, 2010 7:58 pm

Thanks for your response. I'm a bit new to this, so I need a little more help.

I run the DownloadFile option to get a rather large file. It times out before it finishes.
I understand from your post that I need to get the size of the file that is on my local drive and then compare it to the size of the file on the remote site. I am using VB6, so the command to get the size of the file on the remote site is (I think):

s = objFTP.GetFileSize(FileName)

Unfortunately this returns a 15. Not nearly the size. It is actually about 800 meg

I then get the size of the file that was downloaded. In my case it usually dies around 6 or 7 hundred meg.

After I establish the fact that the entire file was not downloaded, I'm not sure what the next line of code would be. I think I run the DownloadFile command again, but this time include the the parameters nRestartLo and nRestartHi. I'm not sure what values to put in each of these parameters.

Is there a snippet of code somewhere on your site that runs through this?

Thanks

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: Restart a download

Post by mb » Tue Dec 21, 2010 8:51 pm

After the GetFileSize returns 0, use the LastFileSize property to get the file size. GetFileSize returns the error code. 0=no error, 15=ftpErrorWrongReply.
Last edited by mb on Tue Dec 21, 2010 8:52 pm, edited 1 time in total.

donj91711
Posts: 33
Joined: Fri Jul 30, 2010 7:01 pm

Re: Restart a download

Post by donj91711 » Tue Dec 21, 2010 10:47 pm

Thank you. I now see how to get the file size.

Now that I can tell that the entire file was not downloaded, how do I resume the download?

Thanks.

mb
Posts: 12026
Joined: Thu Oct 11, 2001 1:24 pm
Display name: Mat (SmartFTP)
Contact:

Re: Restart a download

Post by mb » Tue Dec 21, 2010 11:41 pm

Pass the filesize into the restart arguments:
objFTP.DownloadFile(FileName, ResultDocPath & FileName, nRestartLo, nRestartHi)

Post Reply