Hollowyearz

Badass_FTP_workingprogressbar

Nov 28th, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.80 KB | None | 0 0
  1. #include <FTPEx.au3>
  2. #include <Misc.au3>
  3. #include <ProgressConstants.au3>
  4. #include <GUIConstantsEx.au3>
  5. #include <Array.au3>
  6.  
  7. $s_LocalFile = FileOpenDialog ( "title", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All Files (*.*)")
  8. $sRemoteFile = StringRegExpReplace($s_LocalFile, ".+\\(.*\..*)$", "/$1")
  9.  
  10. Local $sServer =        IniRead(@ScriptDir & "\LogonInfo.ini", "FTPLogonInfo", "HostName", "Default Value")
  11. Local $sUsername =  IniRead(@ScriptDir & "\LogonInfo.ini", "FTPLogonInfo", "UserName", "Default Value")
  12. Local $sPass =          iniRead(@ScriptDir & "\LogonInfo.ini", "FTPLogonInfo", "PassWord", "Default Value")
  13.  
  14. Local $hInternetSession = _FTP_Open('MyFTP Control')
  15. ; passive allows most protected FTPs to answer
  16. Local $hFTPSession = _FTP_Connect($hInternetSession, $sServer, $sUsername, $sPass, 1)
  17.  
  18. Global $idProgressBarCtrl, $idBtn_Cancel
  19. _uploadProgress()
  20.  
  21. _FTP_Close($hInternetSession)
  22.  
  23. Func _uploadProgress()
  24.     ; create GUI
  25.     GUICreate("FTP Upload", 220, 100, 100, 200)
  26.     GUICtrlCreateLabel("Uploading:  " & $sRemoteFile, 10, 10)
  27.     $idProgressBarCtrl = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
  28.     GUICtrlSetColor(-1, 32250); not working with Windows XP Style
  29.     $idBtn_Cancel = GUICtrlCreateButton("Cancel", 75, 70, 70, 20)
  30.     GUISetState()
  31.  
  32.     Local $sFunctionToCall = "_UpdateGUIProgressBar"
  33.     _FTP_ProgressUpload($hFTPSession, $s_LocalFile, $sRemoteFile, $sFunctionToCall)
  34.     Exit @error
  35. EndFunc   ;==>Example
  36.  
  37. Func _UpdateGUIProgressBar($iPercent)
  38.     GUICtrlSetData($idProgressBarCtrl, $iPercent)
  39.     Switch GUIGetMsg()
  40.         Case $GUI_EVENT_CLOSE
  41.             Return -1 ; _FTP_UploadProgress Aborts with -1, so you can exit your app afterwards
  42.         Case $idBtn_Cancel
  43.             Return -2 ; Just Cancel, without special Return value
  44.     EndSwitch
  45.     Return 1 ; Otherwise continue Upload
  46. EndFunc   ;==>_UpdateGUIProgressBar
Advertisement
Add Comment
Please, Sign In to add comment