FTPEx_En.au3 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. #include-once
  2. #include "Date.au3"
  3. #include "FileConstants.au3"
  4. #include "StructureConstants.au3"
  5. #include "WinAPIConv.au3"
  6. #include "WinAPIError.au3"
  7. ; #INDEX# =======================================================================================================================
  8. ; Title .........: FTP
  9. ; AutoIt Version : 3.3.14.5
  10. ; Language ......: English
  11. ; Description ...: Functions that assist with FTP.
  12. ; Author(s) .....: Wouter, Prog@ndy, jpm, Beege
  13. ; Notes .........: based on FTP_Ex.au3 16/02/2009 http://www.autoit.de/index.php?page=Thread&postID=48393
  14. ; ===============================================================================================================================
  15. ; #VARIABLES# ===================================================================================================================
  16. Global $__g_hWinInet_FTP = -1
  17. Global $__g_hCallback_FTP, $__g_bCallback_FTP = False
  18. ; ===============================================================================================================================
  19. ; #CONSTANTS# ===================================================================================================================
  20. Global Const $INTERNET_OPEN_TYPE_DIRECT = 1
  21. Global Const $INTERNET_OPEN_TYPE_PRECONFIG = 0
  22. Global Const $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
  23. Global Const $INTERNET_OPEN_TYPE_PROXY = 3
  24. Global Const $FTP_TRANSFER_TYPE_UNKNOWN = 0 ;Defaults to FTP_TRANSFER_TYPE_BINARY.
  25. Global Const $FTP_TRANSFER_TYPE_ASCII = 1 ;Type A transfer method. Control and formatting information is converted to local equivalents.
  26. Global Const $FTP_TRANSFER_TYPE_BINARY = 2 ;Type I transfer method. The file is transferred exactly as it exists with no changes.
  27. Global Const $INTERNET_FLAG_DEFAULT = 0
  28. Global Const $INTERNET_FLAG_PASSIVE = 0x08000000
  29. Global Const $INTERNET_FLAG_TRANSFER_ASCII = $FTP_TRANSFER_TYPE_ASCII
  30. Global Const $INTERNET_FLAG_TRANSFER_BINARY = $FTP_TRANSFER_TYPE_BINARY
  31. Global Const $INTERNET_DEFAULT_FTP_PORT = 21
  32. Global Const $INTERNET_SERVICE_FTP = 1
  33. Global Const $INTERNET_SERVICE_GOPHER = 2
  34. Global Const $INTERNET_SERVICE_HTTP = 3
  35. ; _FTP_FindFileFirst flags
  36. Global Const $INTERNET_FLAG_HYPERLINK = 0x00000400
  37. Global Const $INTERNET_FLAG_NEED_FILE = 0x00000010
  38. Global Const $INTERNET_FLAG_NO_CACHE_WRITE = 0x04000000
  39. Global Const $INTERNET_FLAG_RELOAD = 0x80000000
  40. Global Const $INTERNET_FLAG_RESYNCHRONIZE = 0x00000800
  41. ; _FTP_Open flags
  42. Global Const $INTERNET_FLAG_ASYNC = 0x10000000
  43. Global Const $INTERNET_FLAG_FROM_CACHE = 0x01000000
  44. Global Const $INTERNET_FLAG_OFFLINE = $INTERNET_FLAG_FROM_CACHE
  45. ; _FTP_...() Status
  46. Global Const $INTERNET_STATUS_CLOSING_CONNECTION = 50
  47. Global Const $INTERNET_STATUS_CONNECTION_CLOSED = 51
  48. Global Const $INTERNET_STATUS_CONNECTING_TO_SERVER = 20
  49. Global Const $INTERNET_STATUS_CONNECTED_TO_SERVER = 21
  50. Global Const $INTERNET_STATUS_CTL_RESPONSE_RECEIVED = 42
  51. Global Const $INTERNET_STATUS_INTERMEDIATE_RESPONSE = 120
  52. Global Const $INTERNET_STATUS_PREFETCH = 43
  53. Global Const $INTERNET_STATUS_REDIRECT = 110
  54. Global Const $INTERNET_STATUS_REQUEST_COMPLETE = 100
  55. Global Const $INTERNET_STATUS_HANDLE_CREATED = 60
  56. Global Const $INTERNET_STATUS_HANDLE_CLOSING = 70
  57. Global Const $INTERNET_STATUS_SENDING_REQUEST = 30
  58. Global Const $INTERNET_STATUS_REQUEST_SENT = 31
  59. Global Const $INTERNET_STATUS_RECEIVING_RESPONSE = 40
  60. Global Const $INTERNET_STATUS_RESPONSE_RECEIVED = 41
  61. Global Const $INTERNET_STATUS_STATE_CHANGE = 200
  62. Global Const $INTERNET_STATUS_RESOLVING_NAME = 10
  63. Global Const $INTERNET_STATUS_NAME_RESOLVED = 11
  64. ; ===============================================================================================================================
  65. ; #CURRENT# =====================================================================================================================
  66. ; _FTP_Close
  67. ; _FTP_Command
  68. ; _FTP_Connect
  69. ; _FTP_DecodeInternetStatus
  70. ; _FTP_DirCreate
  71. ; _FTP_DirDelete
  72. ; _FTP_DirGetCurrent
  73. ; _FTP_DirPutContents
  74. ; _FTP_DirSetCurrent
  75. ; _FTP_FileClose
  76. ; _FTP_FileDelete
  77. ; _FTP_FileGet
  78. ; _FTP_FileGetSize
  79. ; _FTP_FileOpen
  80. ; _FTP_FilePut
  81. ; _FTP_FileRead
  82. ; _FTP_FileRename
  83. ; _FTP_FileTimeLoHiToStr
  84. ; _FTP_FindFileClose
  85. ; _FTP_FindFileFirst
  86. ; _FTP_FindFileNext
  87. ; _FTP_GetLastResponseInfo
  88. ; _FTP_ListToArray
  89. ; _FTP_ListToArray2D
  90. ; _FTP_ListToArrayEx
  91. ; _FTP_Open
  92. ; _FTP_ProgressDownload
  93. ; _FTP_ProgressUpload
  94. ; _FTP_SetStatusCallback
  95. ; ===============================================================================================================================
  96. ; #INTERNAL_USE_ONLY#============================================================================================================
  97. ; __FTP_ListToArray
  98. ; __FTP_Init
  99. ; ===============================================================================================================================
  100. ; #FUNCTION# ====================================================================================================================
  101. ; Author ........: Wouter van Kesteren
  102. ; Modified.......: Beege
  103. ; ===============================================================================================================================
  104. Func _FTP_Close($hSession)
  105. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  106. Local $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $hSession)
  107. If @error Or $aDone[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  108. If $__g_bCallback_FTP = True Then DllCallbackFree($__g_hCallback_FTP)
  109. Return $aDone[0]
  110. EndFunc ;==>_FTP_Close
  111. ; #FUNCTION# ====================================================================================================================
  112. ; Author ........: Bill Mezian
  113. ; Modified.......:
  114. ; ===============================================================================================================================
  115. Func _FTP_Command($hFTPSession, $sFTPCommand, $iFlags = $FTP_TRANSFER_TYPE_ASCII, $iExpectResponse = 0, $iContext = 0)
  116. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  117. Local $ai_FTPCommand = DllCall($__g_hWinInet_FTP, 'bool', 'FtpCommandW', 'handle', $hFTPSession, 'bool', $iExpectResponse, 'dword', $iFlags, 'wstr', $sFTPCommand, 'dword_ptr', $iContext, 'ptr*', 0)
  118. If @error Or $ai_FTPCommand[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  119. Return SetError(0, $ai_FTPCommand[6], $ai_FTPCommand[0])
  120. EndFunc ;==>_FTP_Command
  121. ; #FUNCTION# ====================================================================================================================
  122. ; Author ........: Wouter van Kesteren
  123. ; Modified.......:
  124. ; ===============================================================================================================================
  125. Func _FTP_Connect($hInternetSession, $sServerName, $sUsername, $sPassword, $iPassive = 0, $iServerPort = 0, $iService = $INTERNET_SERVICE_FTP, $iFlags = 0, $fuContext = 0)
  126. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  127. If $iPassive == 1 Then $iFlags = BitOR($iFlags, $INTERNET_FLAG_PASSIVE)
  128. Local $ai_InternetConnect = DllCall($__g_hWinInet_FTP, 'hwnd', 'InternetConnectW', 'handle', $hInternetSession, 'wstr', $sServerName, 'ushort', $iServerPort, 'wstr', $sUsername, 'wstr', $sPassword, 'dword', $iService, 'dword', $iFlags, 'dword_ptr', $fuContext)
  129. If @error Or $ai_InternetConnect[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  130. Return $ai_InternetConnect[0]
  131. EndFunc ;==>_FTP_Connect
  132. ; #FUNCTION# ====================================================================================================================
  133. ; Author ........: Beege
  134. ; Modified.......: jpm
  135. ; ===============================================================================================================================
  136. Func _FTP_DecodeInternetStatus($iInternetStatus)
  137. Switch $iInternetStatus
  138. Case $INTERNET_STATUS_CLOSING_CONNECTION
  139. Return 'Closing connection ...'
  140. Case $INTERNET_STATUS_CONNECTION_CLOSED
  141. Return 'Connection closed'
  142. Case $INTERNET_STATUS_CONNECTING_TO_SERVER
  143. Return 'Connecting to server ...'
  144. Case $INTERNET_STATUS_CONNECTED_TO_SERVER
  145. Return 'Connected to server'
  146. Case $INTERNET_STATUS_CTL_RESPONSE_RECEIVED
  147. Return 'CTL esponse received'
  148. Case $INTERNET_STATUS_INTERMEDIATE_RESPONSE
  149. Return 'Intermediate response'
  150. Case $INTERNET_STATUS_PREFETCH
  151. Return 'Prefetch'
  152. Case $INTERNET_STATUS_REDIRECT
  153. Return 'Redirect'
  154. Case $INTERNET_STATUS_REQUEST_COMPLETE
  155. Return 'Request complete'
  156. Case $INTERNET_STATUS_HANDLE_CREATED
  157. Return 'Handle created'
  158. Case $INTERNET_STATUS_HANDLE_CLOSING
  159. Return 'Handle closing ...'
  160. Case $INTERNET_STATUS_SENDING_REQUEST
  161. Return 'Sending request ...'
  162. Case $INTERNET_STATUS_REQUEST_SENT
  163. Return 'Request sent'
  164. Case $INTERNET_STATUS_RECEIVING_RESPONSE
  165. Return 'Receiving response ...'
  166. Case $INTERNET_STATUS_RESPONSE_RECEIVED
  167. Return 'Response received'
  168. Case $INTERNET_STATUS_STATE_CHANGE
  169. Return 'State change'
  170. Case $INTERNET_STATUS_RESOLVING_NAME
  171. Return 'Resolving name ...'
  172. Case $INTERNET_STATUS_NAME_RESOLVED
  173. Return 'Name resolved'
  174. Case Else
  175. Return 'UNKNOWN status = ' & $iInternetStatus
  176. EndSwitch
  177. EndFunc ;==>_FTP_DecodeInternetStatus
  178. ; #FUNCTION# ====================================================================================================================
  179. ; Author ........: Wouter van Kesteren
  180. ; Modified.......:
  181. ; ===============================================================================================================================
  182. Func _FTP_DirCreate($hFTPSession, $sRemote)
  183. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  184. Local $ai_FTPMakeDir = DllCall($__g_hWinInet_FTP, 'bool', 'FtpCreateDirectoryW', 'handle', $hFTPSession, 'wstr', $sRemote)
  185. If @error Or $ai_FTPMakeDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  186. Return $ai_FTPMakeDir[0]
  187. EndFunc ;==>_FTP_DirCreate
  188. ; #FUNCTION# ====================================================================================================================
  189. ; Author ........: Wouter van Kesteren
  190. ; Modified.......:
  191. ; ===============================================================================================================================
  192. Func _FTP_DirDelete($hFTPSession, $sRemote)
  193. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  194. Local $ai_FTPDelDir = DllCall($__g_hWinInet_FTP, 'bool', 'FtpRemoveDirectoryW', 'handle', $hFTPSession, 'wstr', $sRemote)
  195. If @error Or $ai_FTPDelDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  196. Return $ai_FTPDelDir[0]
  197. EndFunc ;==>_FTP_DirDelete
  198. ; #FUNCTION# ====================================================================================================================
  199. ; Author ........: Beast
  200. ; Modified.......:
  201. ; ===============================================================================================================================
  202. Func _FTP_DirGetCurrent($hFTPSession)
  203. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  204. Local $ai_FTPGetCurrentDir = DllCall($__g_hWinInet_FTP, 'bool', 'FtpGetCurrentDirectoryW', 'handle', $hFTPSession, 'wstr', "", 'dword*', 260)
  205. If @error Or $ai_FTPGetCurrentDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  206. Return $ai_FTPGetCurrentDir[2]
  207. EndFunc ;==>_FTP_DirGetCurrent
  208. ; #FUNCTION# ====================================================================================================================
  209. ; Author ........: Stumpii
  210. ; Modified.......:
  211. ; ===============================================================================================================================
  212. Func _FTP_DirPutContents($hFTPSession, $sLocalFolder, $sRemoteFolder, $bRecursivePut, $iContext = 0)
  213. If StringRight($sLocalFolder, 1) == "\" Then $sLocalFolder = StringTrimRight($sLocalFolder, 1)
  214. ; Shows the filenames of all files in the current directory.
  215. Local $hSearch = FileFindFirstFile($sLocalFolder & "\*.*")
  216. ; Check if the search was successful
  217. If $hSearch = -1 Then Return SetError(1, 0, 0)
  218. Local $sFile
  219. While 1
  220. $sFile = FileFindNextFile($hSearch)
  221. If @error Then ExitLoop
  222. If StringInStr(FileGetAttrib($sLocalFolder & "\" & $sFile), "D") Then
  223. _FTP_DirCreate($hFTPSession, $sRemoteFolder & "/" & $sFile)
  224. If $bRecursivePut Then
  225. _FTP_DirPutContents($hFTPSession, $sLocalFolder & "\" & $sFile, $sRemoteFolder & "/" & $sFile, $bRecursivePut, $iContext)
  226. EndIf
  227. Else
  228. _FTP_FilePut($hFTPSession, $sLocalFolder & "\" & $sFile, $sRemoteFolder & "/" & $sFile, 0, $iContext)
  229. EndIf
  230. WEnd
  231. ; Close the search handle
  232. FileClose($hSearch)
  233. Return 1
  234. EndFunc ;==>_FTP_DirPutContents
  235. ; #FUNCTION# ====================================================================================================================
  236. ; Author ........: Beast
  237. ; Modified.......:
  238. ; ===============================================================================================================================
  239. Func _FTP_DirSetCurrent($hFTPSession, $sRemote)
  240. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  241. Local $ai_FTPSetCurrentDir = DllCall($__g_hWinInet_FTP, 'bool', 'FtpSetCurrentDirectoryW', 'handle', $hFTPSession, 'wstr', $sRemote)
  242. If @error Or $ai_FTPSetCurrentDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  243. Return $ai_FTPSetCurrentDir[0]
  244. EndFunc ;==>_FTP_DirSetCurrent
  245. ; #FUNCTION# ====================================================================================================================
  246. ; Author ........: joeyb1275
  247. ; Modified.......: Prog@ndy
  248. ; ===============================================================================================================================
  249. Func _FTP_FileClose($hFTPFile)
  250. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  251. Local $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $hFTPFile)
  252. If @error Or $aDone[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  253. Return $aDone[0]
  254. EndFunc ;==>_FTP_FileClose
  255. ; #FUNCTION# ====================================================================================================================
  256. ; Author ........: Wouter van Kesteren
  257. ; Modified.......:
  258. ; ===============================================================================================================================
  259. Func _FTP_FileDelete($hFTPSession, $sRemoteFile)
  260. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  261. Local $ai_FTPPutFile = DllCall($__g_hWinInet_FTP, 'bool', 'FtpDeleteFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile)
  262. If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  263. Return $ai_FTPPutFile[0]
  264. EndFunc ;==>_FTP_FileDelete
  265. ; #FUNCTION# ====================================================================================================================
  266. ; Author ........: Wouter van Kesteren
  267. ; Modified.......:
  268. ; ===============================================================================================================================
  269. Func _FTP_FileGet($hFTPSession, $sRemoteFile, $sLocalFile, $bFailIfExists = False, $iFlagsAndAttributes = 0, $iFlags = $FTP_TRANSFER_TYPE_UNKNOWN, $iContext = 0)
  270. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  271. Local $ai_FTPGetFile = DllCall($__g_hWinInet_FTP, 'bool', 'FtpGetFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile, 'wstr', $sLocalFile, 'bool', $bFailIfExists, 'dword', $iFlagsAndAttributes, 'dword', $iFlags, 'dword_ptr', $iContext)
  272. If @error Or $ai_FTPGetFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  273. Return $ai_FTPGetFile[0]
  274. EndFunc ;==>_FTP_FileGet
  275. ; #FUNCTION# ====================================================================================================================
  276. ; Author ........: Joachim de Koning
  277. ; Modified.......: jpm
  278. ; ===============================================================================================================================
  279. Func _FTP_FileGetSize($hFTPSession, $sFileName)
  280. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  281. Local $ai_FTPGetSizeHandle = DllCall($__g_hWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hFTPSession, 'wstr', $sFileName, 'dword', $GENERIC_READ, 'dword', $INTERNET_FLAG_NO_CACHE_WRITE + $INTERNET_FLAG_TRANSFER_BINARY, 'dword_ptr', 0)
  282. If @error Or $ai_FTPGetSizeHandle[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  283. Local $ai_FTPGetFileSize = DllCall($__g_hWinInet_FTP, 'dword', 'FtpGetFileSize', 'handle', $ai_FTPGetSizeHandle[0], 'dword*', 0)
  284. If @error Or $ai_FTPGetFileSize[0] = 0 Then
  285. Local $iLasterror = _WinAPI_GetLastError()
  286. DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FTPGetSizeHandle[0])
  287. ; No need to test @error.
  288. Return SetError(-1, $iLasterror, 0)
  289. EndIf
  290. DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FTPGetSizeHandle[0])
  291. ; No need to test @error.
  292. Return _WinAPI_MakeQWord($ai_FTPGetFileSize[0], $ai_FTPGetFileSize[2])
  293. EndFunc ;==>_FTP_FileGetSize
  294. ; #FUNCTION# ====================================================================================================================
  295. ; Author ........: joeyb1275
  296. ; Modified.......: Prog@ndy
  297. ; ===============================================================================================================================
  298. Func _FTP_FileOpen($hConnect, $sFileName, $iAccess = $GENERIC_READ, $iFlags = $INTERNET_FLAG_TRANSFER_BINARY, $iContext = 0)
  299. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  300. Local $ai_FtpOpenfile = DllCall($__g_hWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hConnect, 'wstr', $sFileName, 'dword', $iAccess, 'dword', $iFlags, 'dword_ptr', $iContext)
  301. If @error Or $ai_FtpOpenfile[0] == 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  302. Return $ai_FtpOpenfile[0]
  303. EndFunc ;==>_FTP_FileOpen
  304. ; #FUNCTION# ====================================================================================================================
  305. ; Author ........: Wouter van Kesteren
  306. ; Modified.......:
  307. ; ===============================================================================================================================
  308. Func _FTP_FilePut($hFTPSession, $sLocalFile, $sRemoteFile, $iFlags = 0, $iContext = 0)
  309. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  310. Local $ai_FTPPutFile = DllCall($__g_hWinInet_FTP, 'bool', 'FtpPutFileW', 'handle', $hFTPSession, 'wstr', $sLocalFile, 'wstr', $sRemoteFile, 'dword', $iFlags, 'dword_ptr', $iContext)
  311. If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  312. Return $ai_FTPPutFile[0]
  313. EndFunc ;==>_FTP_FilePut
  314. ; #FUNCTION# ====================================================================================================================
  315. ; Author ........: joeyb1275
  316. ; Modified.......: Prog@ndy
  317. ; ===============================================================================================================================
  318. Func _FTP_FileRead($hFTPFile, $iNumberOfBytesToRead)
  319. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  320. Local $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")
  321. Local $ai_FTPReadFile = DllCall($__g_hWinInet_FTP, 'bool', 'InternetReadFile', 'handle', $hFTPFile, 'struct*', $tBuffer, 'dword', $iNumberOfBytesToRead, 'dword*', 0) ;LPDWORD lpdwNumberOfBytesRead
  322. If @error Then Return SetError(1, _WinAPI_GetLastError(), 0)
  323. Local $iNumberOfBytesRead = $ai_FTPReadFile[4]
  324. If $iNumberOfBytesRead == 0 And $ai_FTPReadFile[0] == 1 Then
  325. Return SetError(-1, 0, 0)
  326. ElseIf $ai_FTPReadFile[0] == 0 Then
  327. Return SetError(2, _WinAPI_GetLastError(), 0)
  328. EndIf
  329. Local $s_FileRead
  330. If $iNumberOfBytesToRead > $iNumberOfBytesRead Then
  331. $s_FileRead = BinaryMid(DllStructGetData($tBuffer, 1), 1, $iNumberOfBytesRead) ;index is omitted so the entire array is written into $s_FileRead as a BinaryString
  332. Else
  333. $s_FileRead = DllStructGetData($tBuffer, 1) ;index is omitted so the entire array is written into $s_FileRead as a BinaryString
  334. EndIf
  335. Return SetError(0, $iNumberOfBytesRead, $s_FileRead)
  336. EndFunc ;==>_FTP_FileRead
  337. ; #FUNCTION# ====================================================================================================================
  338. ; Author ........: Wouter van Kesteren
  339. ; Modified.......:
  340. ; ===============================================================================================================================
  341. Func _FTP_FileRename($hFTPSession, $sExisting, $sNew)
  342. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  343. Local $ai_FTPRenameFile = DllCall($__g_hWinInet_FTP, 'bool', 'FtpRenameFileW', 'handle', $hFTPSession, 'wstr', $sExisting, 'wstr', $sNew)
  344. If @error Or $ai_FTPRenameFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  345. Return $ai_FTPRenameFile[0]
  346. EndFunc ;==>_FTP_FileRename
  347. ; #FUNCTION# ====================================================================================================================
  348. ; Author ........: Prog@ndy
  349. ; Modified.......:
  350. ; ===============================================================================================================================
  351. Func _FTP_FileTimeLoHiToStr($iLoDWORD, $iHiDWORD, $iFmt = 0)
  352. Local $tFileTime = DllStructCreate($tagFILETIME)
  353. If Not $iLoDWORD And Not $iHiDWORD Then Return SetError(1, 0, "")
  354. DllStructSetData($tFileTime, 1, $iLoDWORD)
  355. DllStructSetData($tFileTime, 2, $iHiDWORD)
  356. Local $sDate = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  357. Return SetError(@error, @extended, $sDate)
  358. EndFunc ;==>_FTP_FileTimeLoHiToStr
  359. ; #FUNCTION# ====================================================================================================================
  360. ; Author ........: Dick Bronsdijk
  361. ; Modified.......: Prog@ndy, jpm
  362. ; ===============================================================================================================================
  363. Func _FTP_FindFileClose($hFTPFind)
  364. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  365. Local $ai_FTPPutFile = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $hFTPFind)
  366. If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), "")
  367. Return $ai_FTPPutFile[0]
  368. EndFunc ;==>_FTP_FindFileClose
  369. ; #FUNCTION# ====================================================================================================================
  370. ; Author ........: Dick Bronsdijk
  371. ; Modified.......: Prog@ndy, jpm
  372. ; ===============================================================================================================================
  373. Func _FTP_FindFileFirst($hFTPSession, $sRemotePath, ByRef $hFTPFind, $iFlags = 0, $iContext = 0)
  374. ;flags = 0 changed to $INTERNET_FLAG_TRANSFER_BINARY to see if stops hanging
  375. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  376. Local $t_DllStruct = DllStructCreate($tagWIN32_FIND_DATA)
  377. If @error Then Return SetError(-3, 0, "")
  378. Local $a_FTPFileList[1]
  379. $a_FTPFileList[0] = 0
  380. Local $ai_FTPFirstFile = DllCall($__g_hWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $hFTPSession, 'wstr', $sRemotePath, 'struct*', $t_DllStruct, 'dword', $iFlags, 'dword_ptr', $iContext)
  381. If @error Or $ai_FTPFirstFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), $ai_FTPFirstFile)
  382. $hFTPFind = $ai_FTPFirstFile[0]
  383. Local $a_FTPFileList[12]
  384. $a_FTPFileList[0] = 11
  385. $a_FTPFileList[1] = DllStructGetData($t_DllStruct, "dwFileAttributes")
  386. $a_FTPFileList[2] = DllStructGetData($t_DllStruct, "ftCreationTime", 1)
  387. $a_FTPFileList[3] = DllStructGetData($t_DllStruct, "ftCreationTime", 2)
  388. $a_FTPFileList[4] = DllStructGetData($t_DllStruct, "ftLastAccessTime", 1)
  389. $a_FTPFileList[5] = DllStructGetData($t_DllStruct, "ftLastAccessTime", 2)
  390. $a_FTPFileList[6] = DllStructGetData($t_DllStruct, "ftLastWriteTime", 1)
  391. $a_FTPFileList[7] = DllStructGetData($t_DllStruct, "ftLastWriteTime", 2)
  392. $a_FTPFileList[8] = DllStructGetData($t_DllStruct, "nFileSizeHigh")
  393. $a_FTPFileList[9] = DllStructGetData($t_DllStruct, "nFileSizeLow")
  394. $a_FTPFileList[10] = DllStructGetData($t_DllStruct, "cFileName")
  395. $a_FTPFileList[11] = DllStructGetData($t_DllStruct, "cAlternateFileName")
  396. Return $a_FTPFileList
  397. EndFunc ;==>_FTP_FindFileFirst
  398. ; #FUNCTION# ====================================================================================================================
  399. ; Author ........: Dick Bronsdijk
  400. ; Modified.......: Prog@ndy, jpm
  401. ; ===============================================================================================================================
  402. Func _FTP_FindFileNext($hFTPFind)
  403. Local $t_DllStruct = DllStructCreate($tagWIN32_FIND_DATA)
  404. Local $a_FTPFileList[1]
  405. $a_FTPFileList[0] = 0
  406. Local $ai_FTPPutFile = DllCall($__g_hWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $hFTPFind, 'struct*', $t_DllStruct)
  407. If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), $a_FTPFileList)
  408. Local $a_FTPFileList[12]
  409. $a_FTPFileList[0] = 11
  410. $a_FTPFileList[1] = DllStructGetData($t_DllStruct, "dwFileAttributes")
  411. $a_FTPFileList[2] = DllStructGetData($t_DllStruct, "ftCreationTime", 1)
  412. $a_FTPFileList[3] = DllStructGetData($t_DllStruct, "ftCreationTime", 2)
  413. $a_FTPFileList[4] = DllStructGetData($t_DllStruct, "ftLastAccessTime", 1)
  414. $a_FTPFileList[5] = DllStructGetData($t_DllStruct, "ftLastAccessTime", 2)
  415. $a_FTPFileList[6] = DllStructGetData($t_DllStruct, "ftLastWriteTime", 1)
  416. $a_FTPFileList[7] = DllStructGetData($t_DllStruct, "ftLastWriteTime", 2)
  417. $a_FTPFileList[8] = DllStructGetData($t_DllStruct, "nFileSizeHigh")
  418. $a_FTPFileList[9] = DllStructGetData($t_DllStruct, "nFileSizeLow")
  419. $a_FTPFileList[10] = DllStructGetData($t_DllStruct, "cFileName")
  420. $a_FTPFileList[11] = DllStructGetData($t_DllStruct, "cAlternateFileName")
  421. Return $a_FTPFileList
  422. EndFunc ;==>_FTP_FindFileNext
  423. ; #FUNCTION# ====================================================================================================================
  424. ; Author ........: jpm
  425. ; Modified.......:
  426. ; ===============================================================================================================================
  427. Func _FTP_GetLastResponseInfo(ByRef $iError, ByRef $sMessage)
  428. Local $ai_LastResponseInfo = DllCall($__g_hWinInet_FTP, 'bool', 'InternetGetLastResponseInfoW', 'dword*', 0, 'wstr', "", 'dword*', 4096)
  429. If @error Or $ai_LastResponseInfo[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  430. $iError = $ai_LastResponseInfo[1]
  431. $sMessage = $ai_LastResponseInfo[2]
  432. Return $ai_LastResponseInfo[0]
  433. EndFunc ;==>_FTP_GetLastResponseInfo
  434. ; #FUNCTION# ====================================================================================================================
  435. ; Author ........: Beast, Prog@ndy
  436. ; Modified.......:
  437. ; ===============================================================================================================================
  438. Func _FTP_ListToArray($hFTPSession, $iReturnType = 0, $iFlags = $INTERNET_FLAG_NO_CACHE_WRITE, $iContext = 0)
  439. Local $aArray[1]
  440. $aArray[0] = 0
  441. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, $aArray)
  442. $aArray = __FTP_ListToArray($hFTPSession, $iReturnType, $iFlags, 0, 1, $iContext)
  443. Return SetError(@error, @extended, $aArray)
  444. EndFunc ;==>_FTP_ListToArray
  445. ; #FUNCTION# ====================================================================================================================
  446. ; Author ........: Prog@ndy
  447. ; Modified.......: jpm
  448. ; ===============================================================================================================================
  449. Func _FTP_ListToArray2D($hFTPSession, $iReturnType = 0, $iFlags = $INTERNET_FLAG_NO_CACHE_WRITE, $iContext = 0)
  450. Local $aArray[1][1]
  451. $aArray[0][0] = 0
  452. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, $aArray)
  453. $aArray = __FTP_ListToArray($hFTPSession, $iReturnType, $iFlags, 0, 2, $iContext)
  454. Return SetError(@error, @extended, $aArray)
  455. EndFunc ;==>_FTP_ListToArray2D
  456. ; #FUNCTION# ====================================================================================================================
  457. ; Author ........: Beast, Prog@ndy
  458. ; Modified.......: jpm
  459. ; ===============================================================================================================================
  460. Func _FTP_ListToArrayEx($hFTPSession, $iReturnType = 0, $iFlags = $INTERNET_FLAG_NO_CACHE_WRITE, $iFmt = 1, $iContext = 0)
  461. Local $aArray[1][1]
  462. $aArray[0][0] = 0
  463. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, $aArray)
  464. $aArray = __FTP_ListToArray($hFTPSession, $iReturnType, $iFlags, $iFmt, 6, $iContext)
  465. Return SetError(@error, @extended, $aArray)
  466. EndFunc ;==>_FTP_ListToArrayEx
  467. ; #FUNCTION# ====================================================================================================================
  468. ; Author ........: Wouter van Kesteren
  469. ; Modified.......:
  470. ; ===============================================================================================================================
  471. Func _FTP_Open($sAgent, $iAccessType = $INTERNET_OPEN_TYPE_DIRECT, $sProxyName = '', $sProxyBypass = '', $iFlags = 0)
  472. If $__g_hWinInet_FTP = -1 Then __FTP_Init()
  473. Local $ai_InternetOpen = DllCall($__g_hWinInet_FTP, 'handle', 'InternetOpenW', 'wstr', $sAgent, 'dword', $iAccessType, _
  474. 'wstr', $sProxyName, 'wstr', $sProxyBypass, 'dword', $iFlags)
  475. If @error Or $ai_InternetOpen[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  476. Return $ai_InternetOpen[0]
  477. EndFunc ;==>_FTP_Open
  478. ; #FUNCTION# ====================================================================================================================
  479. ; Author ........: limette, Prog@ndy
  480. ; Modified.......: jchd
  481. ; ===============================================================================================================================
  482. Func _FTP_ProgressDownload($hFTPSession, $sLocalFile, $sRemoteFile, $hFunctionToCall = 0)
  483. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  484. Local $hFile = FileOpen($sLocalFile, $FO_OVERWRITE + $FO_BINARY)
  485. If $hFile < 0 Then Return SetError(-1, 0, 0)
  486. Local $ai_FtpOpenfile = DllCall($__g_hWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile, 'dword', $GENERIC_READ, 'dword', $FTP_TRANSFER_TYPE_BINARY, 'dword_ptr', 0)
  487. If @error Or $ai_FtpOpenfile[0] = 0 Then Return SetError(-3, _WinAPI_GetLastError(), 0)
  488. Local $ai_FTPGetFileSize = DllCall($__g_hWinInet_FTP, 'dword', 'FtpGetFileSize', 'handle', $ai_FtpOpenfile[0], 'dword*', 0)
  489. If @error Then Return SetError(-2, _WinAPI_GetLastError(), 0)
  490. If Not IsFunc($hFunctionToCall) Then ProgressOn("FTP Download", "Downloading " & $sLocalFile)
  491. Local $iLen = _WinAPI_MakeQWord($ai_FTPGetFileSize[0], $ai_FTPGetFileSize[2]) ;FileGetSize($sRemoteFile)
  492. Local Const $iChunkSize = 256 * 1024
  493. Local $iLast = Mod($iLen, $iChunkSize)
  494. Local $iParts = Ceiling($iLen / $iChunkSize)
  495. Local $tBuffer = DllStructCreate("byte[" & $iChunkSize & "]")
  496. Local $aDone, $ai_FTPread, $iOut, $iRet, $iLasterror
  497. Local $x = $iChunkSize
  498. Local $iDone = 0
  499. For $i = 1 To $iParts
  500. If $i = $iParts And $iLast > 0 Then
  501. $x = $iLast
  502. EndIf
  503. $ai_FTPread = DllCall($__g_hWinInet_FTP, 'bool', 'InternetReadFile', 'handle', $ai_FtpOpenfile[0], 'struct*', $tBuffer, 'dword', $x, 'dword*', $iOut)
  504. If @error Or $ai_FTPread[0] = 0 Then
  505. $iLasterror = _WinAPI_GetLastError()
  506. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  507. ; No need to test @error.
  508. FileClose($hFile)
  509. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  510. Return SetError(-4, $iLasterror, 0)
  511. EndIf
  512. $iRet = FileWrite($hFile, BinaryMid(DllStructGetData($tBuffer, 1), 1, $ai_FTPread[4]))
  513. If Not $iRet Then
  514. $iLasterror = _WinAPI_GetLastError()
  515. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  516. ; No need to test @error.
  517. FileClose($hFile)
  518. FileDelete($sLocalFile)
  519. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  520. Return SetError(-7, $iLasterror, 0)
  521. EndIf
  522. $iDone += $ai_FTPread[4]
  523. If Not IsFunc($hFunctionToCall) Then
  524. ProgressSet(($iDone / $iLen) * 100)
  525. Else
  526. $iRet = $hFunctionToCall(($iDone / $iLen) * 100)
  527. If $iRet <= 0 Then
  528. $iLasterror = @error
  529. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  530. ; No need to test @error.
  531. FileClose($hFile)
  532. FileDelete($sLocalFile)
  533. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  534. Return SetError(-6, $iLasterror, $iRet)
  535. EndIf
  536. EndIf
  537. Sleep(10)
  538. Next
  539. FileClose($hFile)
  540. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  541. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  542. If @error Or $aDone[0] = 0 Then
  543. Return SetError(-5, _WinAPI_GetLastError(), 0)
  544. EndIf
  545. Return 1
  546. EndFunc ;==>_FTP_ProgressDownload
  547. ; #FUNCTION# ====================================================================================================================
  548. ; Author ........: limette, Prog@ndy
  549. ; Modified.......: jchd
  550. ; ===============================================================================================================================
  551. Func _FTP_ProgressUpload($hFTPSession, $sLocalFile, $sRemoteFile, $hFunctionToCall = 0)
  552. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  553. Local $hFile = FileOpen($sLocalFile, $FO_BINARY)
  554. If @error Then Return SetError(-1, _WinAPI_GetLastError(), 0)
  555. Local $ai_FtpOpenfile = DllCall($__g_hWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile, 'dword', $GENERIC_WRITE, 'dword', $FTP_TRANSFER_TYPE_BINARY, 'dword_ptr', 0)
  556. If @error Or $ai_FtpOpenfile[0] = 0 Then Return SetError(-3, _WinAPI_GetLastError(), 0)
  557. If Not IsFunc($hFunctionToCall) Then ProgressOn("FTP Upload", "Uploading " & $sLocalFile)
  558. Local $iLen = FileGetSize($sLocalFile)
  559. Local Const $iChunkSize = 256 * 1024
  560. Local $iLast = Mod($iLen, $iChunkSize)
  561. Local $iParts = Ceiling($iLen / $iChunkSize)
  562. Local $tBuffer = DllStructCreate("byte[" & $iChunkSize & "]")
  563. Local $aDone, $ai_FtpWrite, $iOut, $iRet, $iLasterror
  564. Local $x = $iChunkSize
  565. Local $iDone = 0
  566. For $i = 1 To $iParts
  567. If $i = $iParts And $iLast > 0 Then
  568. $x = $iLast
  569. EndIf
  570. DllStructSetData($tBuffer, 1, FileRead($hFile, $x))
  571. $ai_FtpWrite = DllCall($__g_hWinInet_FTP, 'bool', 'InternetWriteFile', 'handle', $ai_FtpOpenfile[0], 'struct*', $tBuffer, 'dword', $x, 'dword*', $iOut)
  572. If @error Or $ai_FtpWrite[0] = 0 Then
  573. $iLasterror = _WinAPI_GetLastError()
  574. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  575. ; No need to test @error.
  576. FileClose($hFile)
  577. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  578. Return SetError(-4, $iLasterror, 0)
  579. EndIf
  580. $iDone += $x
  581. If Not IsFunc($hFunctionToCall) Then
  582. ProgressSet(($iDone / $iLen) * 100)
  583. Else
  584. $iRet = $hFunctionToCall(($iDone / $iLen) * 100)
  585. If $iRet <= 0 Then
  586. $iLasterror = @error
  587. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  588. ; No need to test @error.
  589. DllCall($__g_hWinInet_FTP, 'bool', 'FtpDeleteFileW', 'handle', $hFTPSession, 'wstr', $sRemoteFile)
  590. ; No need to test @error.
  591. FileClose($hFile)
  592. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  593. Return SetError(-6, $iLasterror, $iRet)
  594. EndIf
  595. EndIf
  596. Sleep(10)
  597. Next
  598. FileClose($hFile)
  599. If Not IsFunc($hFunctionToCall) Then ProgressOff()
  600. $aDone = DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FtpOpenfile[0])
  601. ; No need to test @error.
  602. If @error Or $aDone[0] = 0 Then Return SetError(-5, _WinAPI_GetLastError(), 0)
  603. Return 1
  604. EndFunc ;==>_FTP_ProgressUpload
  605. ; FUNCTION# ====================================================================================================================
  606. ; Name...........: _FTP_SetStatusCallback
  607. ; Description ...: Registers callback function that WinINet functions can call as progress is made during an operation.
  608. ; Syntax.........: _InternetSetStatusCallback ($hInternetSession, $sFunctionName )
  609. ; Parameters ....: $hInternetSession - as returned by _FTP_Open().
  610. ; $sFunctionName - The name of the User Defined Function to call
  611. ; Return values .: Success - Pointer to callback function
  612. ; Failure - 0 and Set @error
  613. ; Author ........: Beege
  614. ; Modified.......: jpm
  615. ; Remarks .......:
  616. ; Related .......: _FTP_DecodeInternetStatus
  617. ; Link ..........: @@MsdnLink@@ InternetSetStatusCallback
  618. ; Example .......: Yes
  619. ; ===============================================================================================================================
  620. Func _FTP_SetStatusCallback($hInternetSession, $sFunctionName)
  621. #Au3Stripper_Ignore_Funcs=$sFunctionName
  622. If $__g_hWinInet_FTP = -1 Then Return SetError(-2, 0, 0)
  623. Local $hCallBack_Register = DllCallbackRegister($sFunctionName, "none", "ptr;ptr;dword;ptr;dword")
  624. If Not $hCallBack_Register Then Return SetError(-1, 0, 0)
  625. Local $ah_CallBackFunction = DllCall('wininet.dll', "ptr", "InternetSetStatusCallback", "ptr", $hInternetSession, "ulong_ptr", DllCallbackGetPtr($hCallBack_Register))
  626. If @error Then Return SetError(-3, 0, 0)
  627. If $ah_CallBackFunction[0] = Ptr(-1) Then Return SetError(-4, 0, 0) ; INTERNET_INVALID_STATUS_CALLBACK
  628. $__g_bCallback_FTP = True
  629. $__g_hCallback_FTP = $hCallBack_Register
  630. Return $ah_CallBackFunction[1]
  631. EndFunc ;==>_FTP_SetStatusCallback
  632. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  633. ; Name...........: __FTP_ListToArray
  634. ; Description ...:
  635. ; Syntax.........: __FTP_ListToArray ( $hFTPSession [, $iReturnType = 0 [, $iFlags = 0 [, $iFmt = 1 [, $iArrayCount = 6 [, $iContext = 0 ]]]]] )
  636. ; Parameters ....:
  637. ; Return values .: an 2D array with the requested info defined by $iArrayCount
  638. ; [0] Filename
  639. ; [1] Filesize
  640. ; [2] FileAttribute
  641. ; [3] File Modification time
  642. ; [4] File Creation time
  643. ; [5] File Access time
  644. ; Author ........: Beast, Prog@ndy
  645. ; Modified.......: jpm (to be use by external UDFs)
  646. ; Remarks .......:
  647. ; Related .......:
  648. ; Link ..........:
  649. ; Example .......:
  650. ; ===============================================================================================================================
  651. Func __FTP_ListToArray($hFTPSession, $iReturnType, $iFlags, $iFmt, $iArrayCount, $iContext)
  652. If $iArrayCount = 1 Then
  653. Local $asFileArray[1], $aDirectoryArray[1]
  654. $asFileArray[0] = 0
  655. Else
  656. Local $asFileArray[1][$iArrayCount], $aDirectoryArray[1][$iArrayCount]
  657. $asFileArray[0][0] = 0
  658. EndIf
  659. If $iReturnType < 0 Or $iReturnType > 2 Then Return SetError(3, 0, $asFileArray)
  660. ; Global Const $tagWIN32_FIND_DATA = "DWORD dwFileAttributes; dword ftCreationTime[2]; dword ftLastAccessTime[2]; dword ftLastWriteTime[2]; DWORD nFileSizeHigh; DWORD nFileSizeLow; dword dwReserved0; dword dwReserved1; WCHAR cFileName[260]; WCHAR cAlternateFileName[14];"
  661. Local $tWIN32_FIND_DATA = DllStructCreate($tagWIN32_FIND_DATA)
  662. Local $iLasterror
  663. Local $aCallFindFirst = DllCall($__g_hWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $hFTPSession, 'wstr', "", 'struct*', $tWIN32_FIND_DATA, 'dword', $iFlags, 'dword_ptr', $iContext)
  664. If @error Or Not $aCallFindFirst[0] Then
  665. $iLasterror = _WinAPI_GetLastError()
  666. If $iLasterror = 12003 Then ; ERROR_INTERNET_EXTENDED_ERROR
  667. Local $iError, $sMessage
  668. _FTP_GetLastResponseInfo($iError, $sMessage)
  669. $iLasterror = $iError
  670. EndIf
  671. Return SetError(1, $iLasterror, $asFileArray)
  672. EndIf
  673. Local $iDirectoryIndex = 0, $sFileIndex = 0
  674. Local $tFileTime, $bIsDir, $aCallFindNext
  675. Do
  676. $bIsDir = BitAND(DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) = $FILE_ATTRIBUTE_DIRECTORY
  677. If $bIsDir And ($iReturnType <> 2) Then
  678. $iDirectoryIndex += 1
  679. If $iArrayCount = 1 Then
  680. If UBound($aDirectoryArray) < $iDirectoryIndex + 1 Then ReDim $aDirectoryArray[$iDirectoryIndex * 2]
  681. $aDirectoryArray[$iDirectoryIndex] = DllStructGetData($tWIN32_FIND_DATA, "cFileName")
  682. Else
  683. If UBound($aDirectoryArray) < $iDirectoryIndex + 1 Then ReDim $aDirectoryArray[$iDirectoryIndex * 2][$iArrayCount]
  684. $aDirectoryArray[$iDirectoryIndex][0] = DllStructGetData($tWIN32_FIND_DATA, "cFileName")
  685. $aDirectoryArray[$iDirectoryIndex][1] = _WinAPI_MakeQWord(DllStructGetData($tWIN32_FIND_DATA, "nFileSizeLow"), DllStructGetData($tWIN32_FIND_DATA, "nFileSizeHigh"))
  686. If $iArrayCount = 6 Then
  687. $aDirectoryArray[$iDirectoryIndex][2] = DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes")
  688. $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastWriteTime"))
  689. $aDirectoryArray[$iDirectoryIndex][3] = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  690. $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftCreationTime"))
  691. $aDirectoryArray[$iDirectoryIndex][4] = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  692. $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastAccessTime"))
  693. $aDirectoryArray[$iDirectoryIndex][5] = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  694. EndIf
  695. EndIf
  696. ElseIf Not $bIsDir And $iReturnType <> 1 Then
  697. $sFileIndex += 1
  698. If $iArrayCount = 1 Then
  699. If UBound($asFileArray) < $sFileIndex + 1 Then ReDim $asFileArray[$sFileIndex * 2]
  700. $asFileArray[$sFileIndex] = DllStructGetData($tWIN32_FIND_DATA, "cFileName")
  701. Else
  702. If UBound($asFileArray) < $sFileIndex + 1 Then ReDim $asFileArray[$sFileIndex * 2][$iArrayCount]
  703. $asFileArray[$sFileIndex][0] = DllStructGetData($tWIN32_FIND_DATA, "cFileName")
  704. $asFileArray[$sFileIndex][1] = _WinAPI_MakeQWord(DllStructGetData($tWIN32_FIND_DATA, "nFileSizeLow"), DllStructGetData($tWIN32_FIND_DATA, "nFileSizeHigh"))
  705. If $iArrayCount = 6 Then
  706. $asFileArray[$sFileIndex][2] = DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes")
  707. $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastWriteTime"))
  708. $asFileArray[$sFileIndex][3] = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  709. $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftCreationTime"))
  710. $asFileArray[$sFileIndex][4] = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  711. $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastAccessTime"))
  712. $asFileArray[$sFileIndex][5] = _Date_Time_FileTimeToStr($tFileTime, $iFmt)
  713. EndIf
  714. EndIf
  715. EndIf
  716. $aCallFindNext = DllCall($__g_hWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $aCallFindFirst[0], 'struct*', $tWIN32_FIND_DATA)
  717. If @error Then
  718. $iLasterror = _WinAPI_GetLastError()
  719. DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $aCallFindFirst[0])
  720. Return SetError(2, $iLasterror, $asFileArray)
  721. EndIf
  722. Until Not $aCallFindNext[0]
  723. DllCall($__g_hWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $aCallFindFirst[0])
  724. ; No need to test @error.
  725. If $iArrayCount = 1 Then
  726. $aDirectoryArray[0] = $iDirectoryIndex
  727. $asFileArray[0] = $sFileIndex
  728. Else
  729. $aDirectoryArray[0][0] = $iDirectoryIndex
  730. $asFileArray[0][0] = $sFileIndex
  731. EndIf
  732. Switch $iReturnType
  733. Case 0
  734. If $iArrayCount = 1 Then
  735. ReDim $aDirectoryArray[$aDirectoryArray[0] + $asFileArray[0] + 1]
  736. For $i = 1 To $sFileIndex
  737. $aDirectoryArray[$aDirectoryArray[0] + $i] = $asFileArray[$i]
  738. Next
  739. $aDirectoryArray[0] += $asFileArray[0]
  740. Else
  741. ReDim $aDirectoryArray[$aDirectoryArray[0][0] + $asFileArray[0][0] + 1][$iArrayCount]
  742. For $i = 1 To $sFileIndex
  743. For $j = 0 To $iArrayCount - 1
  744. $aDirectoryArray[$aDirectoryArray[0][0] + $i][$j] = $asFileArray[$i][$j]
  745. Next
  746. Next
  747. $aDirectoryArray[0][0] += $asFileArray[0][0]
  748. EndIf
  749. Return $aDirectoryArray
  750. Case 1
  751. If $iArrayCount = 1 Then
  752. ReDim $aDirectoryArray[$iDirectoryIndex + 1]
  753. Else
  754. ReDim $aDirectoryArray[$iDirectoryIndex + 1][$iArrayCount]
  755. EndIf
  756. Return $aDirectoryArray
  757. Case 2
  758. If $iArrayCount = 1 Then
  759. ReDim $asFileArray[$sFileIndex + 1]
  760. Else
  761. ReDim $asFileArray[$sFileIndex + 1][$iArrayCount]
  762. EndIf
  763. Return $asFileArray
  764. EndSwitch
  765. EndFunc ;==>__FTP_ListToArray
  766. ; #INTERNAL_USE_ONLY# ===========================================================================================================
  767. ; Name...........: __FTP_Init
  768. ; Description ...: DllOpen wininet.dll
  769. ; Syntax.........: __FTP_Init ( )
  770. ; Parameters ....:
  771. ; Return values .:
  772. ; Author ........:
  773. ; Modified.......:
  774. ; Remarks .......:
  775. ; Related .......:
  776. ; Link ..........:
  777. ; Example .......:
  778. ; ===============================================================================================================================
  779. Func __FTP_Init()
  780. $__g_hWinInet_FTP = DllOpen('wininet.dll')
  781. EndFunc ;==>__FTP_Init