FTP Upload Example Autolt


SUBMITTED BY: Guest

DATE: May 29, 2013, 7:05 a.m.

FORMAT: Text only

SIZE: 5.3 kB

HITS: 2045

  1. #include <FTPEx.au3>
  2. #include <ButtonConstants.au3>
  3. #include <EditConstants.au3>
  4. #include <GUIConstantsEx.au3>
  5. #include <StaticConstants.au3>
  6. #include <WindowsConstants.au3>
  7. #include "Toast.au3"
  8. #include "Marquee.au3"
  9. Global $aMarquee[8], $Round
  10. Global $filenme, $filename, $open1
  11. Global $sMsg, $hProgress, $aRet[2]
  12. #Region ### START Koda GUI section ### Form=
  13. $Form1 = GUICreate("Tony's FTP Upload Client", 442, 327, 205, 130)
  14. GUISetBkColor(0x008000)
  15. $Input1 = GUICtrlCreateInput(IniRead("Default.ini", "Login", "Host", "Host") , 16, 72, 401, 21)
  16. GUICtrlSetBkColor(-1, 0xC8C8C8)
  17. GUICtrlSetTip(-1, "Enter Host name or IP")
  18. $Input2 = GUICtrlCreateInput(IniRead("Default.ini", "Login", "User", "User"), 16, 112, 193, 21)
  19. GUICtrlSetBkColor(-1, 0xC8C8C8)
  20. GUICtrlSetTip(-1, "Enter Your Username")
  21. $Input3 = GUICtrlCreateInput(IniRead("Default.ini", "Login", "Pass", "Password"), 224, 112, 193, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
  22. GUICtrlSetBkColor(-1, 0xC8C8C8)
  23. GUICtrlSetTip(-1, "Enter Your Password")
  24. $Label1 = GUICtrlCreateLabel("FTP Upload", 120, 16, 186, 41)
  25. GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
  26. $Input4 = GUICtrlCreateInput(IniRead("Default.ini", "Login", "Public", "/public_html/"), 16, 152, 193, 21)
  27. GUICtrlSetBkColor(-1, 0xBFCDDB)
  28. GUICtrlSetTip(-1, "Optional")
  29. $Input5 = GUICtrlCreateInput(IniRead("Default.ini", "Login", "Folder", " "), 224, 152, 193, 21)
  30. GUICtrlSetBkColor(-1, 0xBFCDDB)
  31. GUICtrlSetTip(-1, "Optional")
  32. $Button1 = GUICtrlCreateButton("Choose File", 152, 184, 121, 25)
  33. $Upload = GUICtrlCreateButton("Log-IN", 152, 232, 121, 49)
  34. $aMarquee[1] = _GUICtrlMarquee_Init()
  35. _GUICtrlMarquee_SetScroll($aMarquee[1], Default, "alternate", "right", 7)
  36. _GUICtrlMarquee_SetDisplay($aMarquee[1], 1, 0xFF0000, 0xFFFBF0, 12, "times new roman")
  37. _GUICtrlMarquee_Create($aMarquee[1], "Waiting For Task", 40, 296, 353, 21)
  38. GUISetState(@SW_SHOW)
  39. #EndRegion ### END Koda GUI section ###
  40. While 1
  41. $nMsg = GUIGetMsg()
  42. Switch $nMsg
  43. Case $GUI_EVENT_CLOSE
  44. Exit
  45. Case $Upload
  46. $host = GUICtrlRead ($Input1)
  47. $user = GUICtrlRead ($Input2)
  48. $pass = GUICtrlRead ($Input3)
  49. $public = GUICtrlRead ($Input4)
  50. $folder = GUICtrlRead ($Input5)
  51. If $open1 = 0 Then
  52. $open = _FTP_Open("MySQL Upload")
  53. If $open Then
  54. $conn = _FTP_Connect($open, $host, $user, $pass, 0, 21)
  55. If $conn Then
  56. _GUICtrlMarquee_Reset($aMarquee[1], "Loged-In")
  57. $open1 = 1
  58. GUICtrlSetData($Upload, "Upload")
  59. Else
  60. _GUICtrlMarquee_Reset($aMarquee[1], "Log-In Error: 102")
  61. FileWriteLine("log.txt", "Error 102: Login Failed")
  62. EndIf
  63. Else
  64. _GUICtrlMarquee_Reset($aMarquee[1], "Error 101: Internet Issues")
  65. FileWriteLine("log.txt", "Error 101: Internet Issues")
  66. EndIf
  67. Else
  68. If $filename = "" Then
  69. FileWriteLine("log.txt", "Error 100: Retardation")
  70. MsgBox(0, "Your Stupid", "You forgot to select a file, Comence facepalming(Error 100)")
  71. Else
  72. $host = GUICtrlRead ($Input1)
  73. $user = GUICtrlRead ($Input2)
  74. $pass = GUICtrlRead ($Input3)
  75. $public = GUICtrlRead ($Input4)
  76. $folder = GUICtrlRead ($Input5)
  77. _FileSize_In_MegaBytes($filename)
  78. EndIf
  79. EndIf
  80. Case $Button1
  81. $filename = FileOpenDialog("File Select", @ScriptDir, "Select File ()", 1 + 4 )
  82. If $filename = "" Then
  83. Else
  84. GUICtrlSetData($Button1, $filename)
  85. _GUICtrlMarquee_Reset($aMarquee[1], "File Selected")
  86. EndIf
  87. EndSwitch
  88. WEnd
  89. Func Upload_it()
  90. $parse = StringSplit($filename, "\")
  91. $num = $parse[0]
  92. $filenme = $parse[$num]
  93. If $conn Then
  94. If $Round > 5 Then
  95. $sMsg = "Upload Started" & @CRLF & @CRLF
  96. $sMsg &= "Program Hidden until completion" & @CRLF & "Upload Size: " & $Round
  97. $aRet = _Toast_Show(0, "Tony's FTP Upload Client", $sMsg, 2)
  98. _Toast_Hide()
  99. EndIf
  100. $ftpp = _FTP_FilePut($conn, $filename, $public & $folder & $filenme)
  101. _GUICtrlMarquee_Reset($aMarquee[1], "Uploading File")
  102. If $ftpp Then
  103. _FTP_Close($open)
  104. $open1 = 0
  105. GUICtrlSetData($Upload, "Log-IN")
  106. ClipPut("http://" & $host & $folder & "/" & $filenme)
  107. _GUICtrlMarquee_Reset($aMarquee[1], "File Uploaded")
  108. FileWriteLine("log.txt", @MON & "/" & @MDAY & "/" & @YEAR & " " &"http://" & $host & $folder & "/" & $filenme)
  109. GUISetState(@SW_SHOW)
  110. Else
  111. FileWriteLine("log.txt", "Error 103: Upload Failed")
  112. _GUICtrlMarquee_Reset($aMarquee[1], "Upload Error: 103")
  113. EndIf
  114. EndIf
  115. EndFunc
  116. Func _FileSize_In_MegaBytes ($File)
  117. $MegaByte = ('1048576')
  118. $FileSizeInBytes = FileGetSize ($File)
  119. $Equal = $FileSizeInBytes / $MegaByte
  120. $Round = Round ($Equal, '2')
  121. If $Round > 5 Then
  122. GUISetState(@SW_HIDE)
  123. Upload_it()
  124. Else
  125. Upload_it()
  126. EndIf
  127. EndFunc

comments powered by Disqus