Jump to content

Recommended Posts

Posted (edited)

Is there a way to measure how many bytes have been downloaded when using _FTP_FileGet? I am trying to get a working Progress bar that actually displays progress.

I tried using the _FTP_ProgressDownload but it doesn't seem to read the progress in real time. The progress bar sits at 0 unitl the download is finished then it goes to 100%.

So far this is what I have BUT the progress bar won't update until I actually open the folder in explorer and hit refresh (F5). O.o Huh? Anyway... It's in two files. I would love some help on this one because it's driving me nuts.

TEST1.EXE

#include <FTPEx.au3>

$latestversion = "1"
$server = "localhost"
$port = 7227

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, "USERNAME", "PASSWORD", 1, $port)
$sFileSize = _FTP_FileGetSize($Conn, "800MBFILE.EXE")
_FTP_Close($Open)

ProgressOn("800MBFILE", "Downloading " & "800MBFILE " & $LatestVersion & "...", "0%", 0, 0)

$_Pid = Run("test2.exe")
$Pct = 0

While ProcessExists ($_Pid)
If $Pct = 100 Then ExitLoop
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
$BytesReceived = FileGetSize(@TempDir & "800MBFILE.EXE") ;Get bytes received
$Pct = Int($BytesReceived / $sFileSize * 100) ;Calculate percentage
ProgressSet($Pct, $Pct & "%") ;Set progress bar
WEnd

ProgressSet(100,"Download Complete!")
Sleep(2000)
ProgressOff()

_FTP_Close($Open)

and TEST2.EXE

#include <FTPEx.au3>

$server = "localhost"
$port = 7227

$Open = _FTP_Open('MyFTP Control')
$Conn = _FTP_Connect($Open, $server, "USERNAME", "PASSWORD", 1, $port)
_FTP_FileGet($Conn,  "800MBFILE.EXE", @TempDir & "800MBFILE.EXE")
_FTP_Close($Open)
Edited by thepaulguy
Posted (edited)

The data is held in a buffer/temporary file until its finshed. Thats why it goes from 0 to 100 so fast. Its possible to get byte progress using _FTP_SetStatusCallback() but it can get a little tricky. _FTP_ProgressDownload() is certainly the easy route. There might have been something wrong in your script if you want to post whatever you tried before.

Edited by Beege
Posted

I went with this instead of the FTPex.au3.

$LatestVersion=1
$Protocol="ftp"
$server = "localhost"
$port = 7227

ProgressOn("800MBFILE", "Downloading " & "800MBFILE " & $LatestVersion & "...", "0%")
$url = $Protocol & "://USERNAME:PASSWORD@" & $Server & ":" & $Port & "/800MBFILE.EXE";Set URL
Local $hDownload = InetGet($url, @TempDir & "800MBFILE.EXE", 1, 1)
$FileSize = InetGetSize($url) ;Get file size

While Not InetGetInfo($hDownload, 2) ;Loop until download is finished
Sleep(500) ;Sleep for half a second to avoid flicker in the progress bar
$BytesReceived = InetGetInfo($hDownload, 0) ;Get bytes received
$Pct = Int($BytesReceived / $FileSize * 100) ;Calculate percentage
ProgressSet($Pct, $Pct & "%") ;Set progress bar
WEnd

ProgressSet(100,"Download Complete!")
Sleep(2000)
ProgressOff()
InetClose($hDownload)
  • 11 years later...
Posted
On 2/29/2012 at 11:28 PM, thepaulguy said:
...
While Not InetGetInfo($hDownload, 2) ;Loop until download is finished
...

it is a bad habit to use values instead of "understandable" names, here "2" instead of $INET_DOWNLOADCOMPLETE.
Unless you want to lose time by reading your code again.

 

Back to topic:

The code you propose here doesn't work for me. I find two issues:

1)
I can see 2 connections to my FTP server, one done by InetGet and one done by InetGetSize. This is strange (I would expect the 2 to use the same connection) but as InetGetSize does not use a connection handle I guess it's by design.

Then, I see the 2 connections staying idle for 2 minutes and then they disconnect from the server with error: 425 Error while transfering data: ECONNABORTED - Connection aborted
 

2)
If I use first InetGetSize and then InetGet, I have only one connection, instead of two. It makes me think there is some tricky stuff here.

 

If I use Example 1 from the help page of _FTP_ProgressDownload, it works perfectly, even the progress bar.
So this is the way to go, IMO.

Philippe
Amiga user

  • 2 weeks later...

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
  • Recently Browsing   0 members

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