Advertisement
Hollowyearz

Badass_FTP_workingprogressbar Copy

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