Jump to content

Restarting a failed download


Paradox
 Share

Recommended Posts

Hey all... Been a while...

I'm invoking the inetget command to start a download of a file. It will begin transfer, and normally doesn't have an issue. I want to put some kind of error handling into my script so that if the file transfer ends prematurely, or if @inetgetbytesread=-1 I want to retry the download from where it left off. This is what I have so far:

inetget($ftp, $rarfilename , 1, 1)  ; Begin downloading file from main server.

guictrlsetdata($status3, "Total Size: " & $ftpsize)   ;Display file size as read by a $ftpsize=inetgetsize($ftp) earlier.
guictrlsetdata($status4, "Total Transferred : " & @InetGetBytesRead) ;Display amount read thus far.

While @InetGetActive  ; While downloading is still active.
    Select
        case @inetgetbytesread <> -1
            guictrlsetdata($status4, "Total Transferred : " & @InetGetBytesRead)
            Sleep(500)
        case @inetgetbytesread = -1
            guictrlsetdata($status4, "Error downloading. Retrying...")
            _filewritelog($logfile, "Error downloading file " & $rarfilename & " from main server. Retrying download.")
            ;Can I just reuse the "inetget($ftp, $rarfilename , 1, 1)" from earlier to restart the download?
            ;If so, will it pick up where it left off?  I'm using FileZilla as my FTP server, is continuing a failed
            ;download something that has to be setup on there? I'm not really sure about that one which is 
            ;why I ask.
        Endselect
Wend

As always, any help would be greatly appreciated.

Edited by Paradox
Link to comment
Share on other sites

maybe...

Dim $rarfilename = "C:\temp.txt"
Dim $ftp = " my web link"

$ftpsize = InetGetSize($ftp)
While $ftpsize <> FileGetSize($rarfilename)
    GetDownload()
    Sleep(100)
WEnd

Func GetDownload()
    InetGet($ftp, $rarfilename, 1, 1)  ; Begin downloading file from main server.

    GUICtrlSetData($status3, "Total Size: " & $ftpsize)   ;Display file size as read by a $ftpsize=inetgetsize($ftp) earlier.
    GUICtrlSetData($status4, "Total Transferred : " & @InetGetBytesRead) ;Display amount read thus far.

    While @InetGetActive  ; While downloading is still active.
        Select
            Case @InetGetBytesRead <> -1
                GUICtrlSetData($status4, "Total Transferred : " & @InetGetBytesRead)
                Sleep(500)
            Case @InetGetBytesRead = -1
                GUICtrlSetData($status4, "Error downloading. Retrying...")
                _FileWriteLog($logfile, "Error downloading file " & $rarfilename & " from main server. Retrying download.")
                InetGet("abort")
                Return
                ;Can I just reuse the "inetget($ftp, $rarfilename , 1, 1)" from earlier to restart the download?
                ;If so, will it pick up where it left off?  I'm using FileZilla as my FTP server, is continuing a failed
                ;download something that has to be setup on there? I'm not really sure about that one which is
                ;why I ask.
        EndSelect
    WEnd
    
EndFunc   ;==>GetDownload

just an idea... not tested

8)

NEWHeader1.png

Link to comment
Share on other sites

maybe...

Dim $rarfilename = "C:\temp.txt"
Dim $ftp = " my web link"

$ftpsize = InetGetSize($ftp)
While $ftpsize <> FileGetSize($rarfilename)
    GetDownload()
    Sleep(100)
WEnd

Func GetDownload()
    InetGet($ftp, $rarfilename, 1, 1)  ; Begin downloading file from main server.

    GUICtrlSetData($status3, "Total Size: " & $ftpsize)   ;Display file size as read by a $ftpsize=inetgetsize($ftp) earlier.
    GUICtrlSetData($status4, "Total Transferred : " & @InetGetBytesRead) ;Display amount read thus far.

    While @InetGetActive  ; While downloading is still active.
        Select
            Case @InetGetBytesRead <> -1
                GUICtrlSetData($status4, "Total Transferred : " & @InetGetBytesRead)
                Sleep(500)
            Case @InetGetBytesRead = -1
                GUICtrlSetData($status4, "Error downloading. Retrying...")
                _FileWriteLog($logfile, "Error downloading file " & $rarfilename & " from main server. Retrying download.")
                InetGet("abort")
                Return
                ;Can I just reuse the "inetget($ftp, $rarfilename , 1, 1)" from earlier to restart the download?
                ;If so, will it pick up where it left off?  I'm using FileZilla as my FTP server, is continuing a failed
                ;download something that has to be setup on there? I'm not really sure about that one which is
                ;why I ask.
        EndSelect
    WEnd
    
EndFunc   ;==>GetDownload

oÝ÷ Ú;¬µ©âu槢Û^²×óú®¢×jIèÁ§íz¹h¢H§«m+Z/z¶ j)ÚÙh¢H§«mè^ââ7ökay"ajÒ,¥u·®²)ජiÖ¬²ç!jëh×6inetget($ftp, $rarfilename, 0, 1)

Why? Because of this (from the help file pertaining to the InetGet command:

reload [optional]

0 = (default) Get the file from local cache if available

1 = Forces a reload from the remote site

Would the 0 imply that it's going to attempt to reload from the existing cache before continuing?

The meaning of the syntax is rather perplexing, and if this DOES work, that I would suggest that the help file be updated to clarify that this is the behavior it will take.

I suppose that the only thing I can do it test it somehow to find out and post the results back up here....

Link to comment
Share on other sites

that would be a good test..

I have seen that however, i have not tested the "reload" option

thats why i put in this InetGet("abort") and looped to start the inetget() over again

let me know what you find out

8)

Well..... It's not looking good so far... Here's my code....

#include <guiconstants.au3>

guicreate("FTP Test",400,250,-1,-1,-1,$WS_EX_TOPMOST)
guisetbkcolor(0xffffff)
Guisetfont(12, 400,0 ,"Courier")
guictrlcreatelabel("Testing FTP download functions.", 2, 10)
$status = guictrlcreatelabel("Current Status:                                 ", 2, 45)
$status2 = guictrlcreatelabel("                                                ", 2, 60)
$status3 = guictrlcreatelabel("                                                ", 2, 77)
$status4 = guictrlcreatelabel("                                                ", 2, 92)
guisetstate(@sw_show)

$file="ftp://xxxxx:xxxxxx@xxxxxxxxx.com/<filename>.exe"  ;Sorry, commented out. It's not my server
$ftpsize = inetgetsize($file)
guictrlsetdata($status2, "File Size: " & $ftpsize & " bytes.")
guictrlsetdata($status3, "Transfered: ")
inetget($file, "xxxxxxxxxx.exe", 0, 1)

while @InetGetActive
    guictrlsetdata($status4, @InetGetBytesRead)
    sleep(250)
        if @inetgetbytesread > ($ftpsize/2) Then
            inetget("abort")
            ExitLoop
        EndIf
wend

guictrlsetdata($status3, "Aborting download to attempt retry...")
sleep(5000)
guictrlsetdata($status3, "Attemping download retry...")
inetget($file, "xxxxxxxxxx.exe", 0, 1)
guictrlsetdata($status3, "Transferred:")
while @InetGetActive
    guictrlsetdata($status4, @InetGetBytesRead)
    sleep(250)
wend
Exit

First I left the script to do it's thing... It downloads, then it aborts, then it downloads again. The problem is that when it aborts, i think it's closing the file. So, to test this theory, i stopped the script while it was downloading and then restarted... Same thing, still 0's out the file when the download starts.

This means 1 of 2 things:

1. AutoIT's command for downloading from FTP doesn't support resuming a file transfer.

or

2. FileZilla Server doesn't support resuming a download to clients.

I can research only one of these (#2), but I'm pretty certain that it's going to wind up being a combined issue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...