Uploads a file in Binary Mode and shows a Progress window or by Calling a User defined Function
#include <FTPEx.au3>
_FTP_ProgressUpload ( $hFTPSession, $sLocalFile, $sRemoteFile [, $hFunctionToCall = 0] )
$hFTPSession | as returned by _FTP_Connect(). |
$sLocalFile | The local file to create. |
$sRemoteFile | The remote source file. |
$hFunctionToCall | [optional] A variable assigned to the user defined function to update a progress bar or react on user interation, such as aborting or exiting the process. Default = none. See remarks. |
Success: | 1. |
Failure: | 0 and sets the @error flag to non-zero. |
@error: | -1 - Local file couldn't be opened -3 - Create File failed -4 - Write to file failed -5 - Close File failed -6 - Download aborted by PercentageFunc and Return of Called Function |
Information about $hFunctionToCall:
Parameter: $iPercentage - The Percentage of Progress
Return Values:
Continue Download - 1
Abort Download - zero or less than zero e.g. 0 or -1
These Return Values are returned by _FTP_ProgressUpload(), too, so you can react on different Actions like Aborting by User, closing App or TimeOut of the process.
#include <FTPEx.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <ProgressConstants.au3>
; This example NEED TO BE ADAPTED to valid $g_sRemoteFile/$sServer/$sUsername/$sPass
;~ Global $g_sRemoteFile = "pub/papers/graphics/research/skin.qt"
Global $g_sRemoteFile = "upload/temp.tmp"
Global $g_sLocalFile = @TempDir & "\temp.tmp"
;~ Local $sServer = 'ftp.cs.brown.edu' ; Brown Computer Science
Local $sServer = 'speedtest.tele2.net' ; Tele2 Speedtest Service
Local $sUsername = ''
Local $sPass = ''
Local $hInternetSession = _FTP_Open('MyFTP Control')
; passive allows most protected FTPs to answer
Local $hFTPSession = _FTP_Connect($hInternetSession, $sServer, $sUsername, $sPass, 1)
Example()
_FTP_Close($hInternetSession)
Func Example()
Local $fuFunctionToCall = _UpdateProgress
ProgressOn("Upload Progress", $g_sRemoteFile)
_FTP_ProgressUpload($hFTPSession, $g_sLocalFile, $g_sRemoteFile, $fuFunctionToCall)
ProgressOff()
EndFunc ;==>Example
Func _UpdateProgress($iPercent)
ProgressSet($iPercent, $iPercent & "%")
If _IsPressed("77") Then Return 0 ; Abort on F8
Return 1 ; Continue upload
EndFunc ;==>_UpdateProgress
#include <FTPEx.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
; This example NEED TO BE ADAPTED to valid $g_sRemoteFile/$sServer/$sUsername/$sPass
;~ Global $g_sRemoteFile = "pub/papers/graphics/research/skin.qt"
Global $g_sRemoteFile = "upload/temp.tmp"
Global $g_sLocalFile = @TempDir & "\temp.tmp"
;~ Local $sServer = 'ftp.cs.brown.edu' ; Brown Computer Science
Local $sServer = 'speedtest.tele2.net' ; Tele2 Speedtest Service
Local $sUsername = ''
Local $sPass = ''
Local $hInternetSession = _FTP_Open('MyFTP Control')
; passive allows most protected FTPs to answer
Local $hFTPSession = _FTP_Connect($hInternetSession, $sServer, $sUsername, $sPass, 1)
Global $g_idProgressBarCtrl, $g_idBtn_Cancel
Example()
_FTP_Close($hInternetSession)
Func Example()
; create GUI
GUICreate("My GUI upload Progressbar", 220, 100, 100, 200)
GUICtrlCreateLabel($g_sRemoteFile, 10, 10)
$g_idProgressBarCtrl = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
GUICtrlSetColor(-1, 32250); not working with Windows XP Style
$g_idBtn_Cancel = GUICtrlCreateButton("Cancel", 75, 70, 70, 20)
GUISetState(@SW_SHOW)
Local $fuFunctionToCall = _UpdateGUIProgressBar
_FTP_ProgressUpload($hFTPSession, $g_sLocalFile, $g_sRemoteFile, $fuFunctionToCall)
Exit @error
EndFunc ;==>Example
Func _UpdateGUIProgressBar($iPercent)
GUICtrlSetData($g_idProgressBarCtrl, $iPercent)
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Return -1 ; _FTP_UploadProgress Aborts with -1, so you can exit your app afterwards
Case $g_idBtn_Cancel
Return -2 ; Just Cancel, without special Return value
EndSwitch
Return 1 ; Otherwise continue Upload
EndFunc ;==>_UpdateGUIProgressBar