1 | #include-once |
---|
2 | |
---|
3 | #include "WinAPIError.au3" |
---|
4 | #include "StructureConstants.au3" |
---|
5 | #include "FileConstants.au3" |
---|
6 | #include "Date.au3" |
---|
7 | |
---|
8 | ; #INDEX# ======================================================================================================================= |
---|
9 | ; Title .........: FTP |
---|
10 | ; AutoIt Version : 3.3.7.20++ |
---|
11 | ; Language ......: English |
---|
12 | ; Description ...: Functions that assist with FTP. |
---|
13 | ; Author(s) .....: Wouter, Prog@ndy, jpm, Beege |
---|
14 | ; Notes .........: based on FTP_Ex.au3 16/02/2009 http://www.autoit.de/index.php?page=Thread&postID=48393 |
---|
15 | ; Dll(s) ........: wininet.dll |
---|
16 | ; =============================================================================================================================== |
---|
17 | |
---|
18 | ; #VARIABLES# =================================================================================================================== |
---|
19 | Global $__ghWinInet_FTP = -1 |
---|
20 | Global $__ghCallback_FTP, $__gbCallback_Set = False |
---|
21 | ; =============================================================================================================================== |
---|
22 | |
---|
23 | ; #CONSTANTS# =================================================================================================================== |
---|
24 | ;~ Global Const $tagWIN32_FIND_DATA = "DWORD dwFileAttributes; dword ftCreationTime[2]; dword ftLastAccessTime[2]; dword ftLastWriteTime[2]; DWORD nFileSizeHigh; DWORD nFileSizeLow; dword dwReserved0; dword dwReserved1; CHAR cFileName[260]; CHAR cAlternateFileName[14];" |
---|
25 | Global Const $INTERNET_OPEN_TYPE_DIRECT = 1 |
---|
26 | Global Const $INTERNET_OPEN_TYPE_PRECONFIG = 0 |
---|
27 | Global Const $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 |
---|
28 | Global Const $INTERNET_OPEN_TYPE_PROXY = 3 |
---|
29 | |
---|
30 | Global Const $FTP_TRANSFER_TYPE_UNKNOWN = 0 ;Defaults to FTP_TRANSFER_TYPE_BINARY. |
---|
31 | Global Const $FTP_TRANSFER_TYPE_ASCII = 1 ;Type A transfer method. Control and formatting information is converted to local equivalents. |
---|
32 | Global Const $FTP_TRANSFER_TYPE_BINARY = 2 ;Type I transfer method. The file is transferred exactly as it exists with no changes. |
---|
33 | |
---|
34 | Global Const $INTERNET_FLAG_PASSIVE = 0x08000000 |
---|
35 | Global Const $INTERNET_FLAG_TRANSFER_ASCII = $FTP_TRANSFER_TYPE_ASCII |
---|
36 | Global Const $INTERNET_FLAG_TRANSFER_BINARY = $FTP_TRANSFER_TYPE_BINARY |
---|
37 | |
---|
38 | Global Const $INTERNET_DEFAULT_FTP_PORT = 21 |
---|
39 | Global Const $INTERNET_SERVICE_FTP = 1 |
---|
40 | |
---|
41 | ;_FTP_FindFileFirst flags |
---|
42 | Global Const $INTERNET_FLAG_HYPERLINK = 0x00000400 |
---|
43 | Global Const $INTERNET_FLAG_NEED_FILE = 0x00000010 |
---|
44 | Global Const $INTERNET_FLAG_NO_CACHE_WRITE = 0x04000000 |
---|
45 | Global Const $INTERNET_FLAG_RELOAD = 0x80000000 |
---|
46 | Global Const $INTERNET_FLAG_RESYNCHRONIZE = 0x00000800 |
---|
47 | |
---|
48 | ;_FTP_Open flags |
---|
49 | Global Const $INTERNET_FLAG_ASYNC = 0x10000000 |
---|
50 | Global Const $INTERNET_FLAG_FROM_CACHE = 0x01000000 |
---|
51 | Global Const $INTERNET_FLAG_OFFLINE = $INTERNET_FLAG_FROM_CACHE |
---|
52 | |
---|
53 | ;_FTP_...() Status |
---|
54 | Global Const $INTERNET_STATUS_CLOSING_CONNECTION = 50 |
---|
55 | Global Const $INTERNET_STATUS_CONNECTION_CLOSED = 51 |
---|
56 | Global Const $INTERNET_STATUS_CONNECTING_TO_SERVER = 20 |
---|
57 | Global Const $INTERNET_STATUS_CONNECTED_TO_SERVER = 21 |
---|
58 | Global Const $INTERNET_STATUS_CTL_RESPONSE_RECEIVED = 42 |
---|
59 | Global Const $INTERNET_STATUS_INTERMEDIATE_RESPONSE = 120 |
---|
60 | Global Const $INTERNET_STATUS_PREFETCH = 43 |
---|
61 | Global Const $INTERNET_STATUS_REDIRECT = 110 |
---|
62 | Global Const $INTERNET_STATUS_REQUEST_COMPLETE = 100 |
---|
63 | Global Const $INTERNET_STATUS_HANDLE_CREATED = 60 |
---|
64 | Global Const $INTERNET_STATUS_HANDLE_CLOSING = 70 |
---|
65 | Global Const $INTERNET_STATUS_SENDING_REQUEST = 30 |
---|
66 | Global Const $INTERNET_STATUS_REQUEST_SENT = 31 |
---|
67 | Global Const $INTERNET_STATUS_RECEIVING_RESPONSE = 40 |
---|
68 | Global Const $INTERNET_STATUS_RESPONSE_RECEIVED = 41 |
---|
69 | Global Const $INTERNET_STATUS_STATE_CHANGE = 200 |
---|
70 | Global Const $INTERNET_STATUS_RESOLVING_NAME = 10 |
---|
71 | Global Const $INTERNET_STATUS_NAME_RESOLVED = 11 |
---|
72 | ; =============================================================================================================================== |
---|
73 | |
---|
74 | ; #OLD_FUNCTIONS#================================================================================================================ |
---|
75 | ; Old Function/Name ; --> New Function/Name/Replacement(s) |
---|
76 | ; |
---|
77 | ; deprecated functions will no longer work, no parameter change just renaming unless stated |
---|
78 | ;_FTP_DownloadProgress ; --> _FTP_ProgressDownload |
---|
79 | ;_FTP_UploadProgress ; --> _FTP_ProgressUpload |
---|
80 | ;_FTPClose ; --> _FTP_Close |
---|
81 | ;_FTPCloseFile ; --> _FTP_FileClose |
---|
82 | ;_FTPCommand ; --> _FTP_Command |
---|
83 | ;_FTPConnect ; --> _FTP_Connect |
---|
84 | ;_FTPDelDir ; --> _FTP_DirDelete |
---|
85 | ;_FTPDelFile ; --> _FTP_FileDelete |
---|
86 | ;_FTPFileFindClose ; --> _FTP_FindFileClose ; $l_DllStruct suppression |
---|
87 | ;_FTPFileFindFirst ; --> _FTP_FindFileFirst ; $l_DllStruct suppression |
---|
88 | ;_FTPFileFindNext ; --> _FTP_FindFileNext ; $l_DllStruct suppression |
---|
89 | ;_FTPFileSizeLoHi ; --> _FTP_FileSizeLoHi |
---|
90 | ;_FTPFilesListto2DArray ; --> _FTP_ListToArray2D |
---|
91 | ;_FTPFilesListtoArray ; --> _FTP_ListToArray |
---|
92 | ;_FTPFilesListtoArrayEx ; --> _FTP_ListToArrayEx ; $b_Fmt added |
---|
93 | ;_FTPFileTimeLoHi ; --> _WinAPI_MakeQWord ; parameter inversion |
---|
94 | ;_FTPFileTimeLoHiToStr ; --> _FTP_FileTimeLoHiToStr ; new optional parameter for type of format |
---|
95 | ;_FTPGetCurrentDir ; --> _FTP_DirGetCurrent |
---|
96 | ;_FTPGetFile ; --> _FTP_FileGet |
---|
97 | ;_FTPGetFileSize ; --> _FTP_FileGetSize |
---|
98 | ;_FTPMakeDir ; --> _FTP_DirCreate |
---|
99 | ;_FTPOpen ; --> _FTP_Open |
---|
100 | ;_FTPOpenFile ; --> _FTP_FileOpen |
---|
101 | ;_FTPPutFile ; --> _FTP_FilePut |
---|
102 | ;_FTPPutFolderContents ; --> _FTP_DirPutContents |
---|
103 | ;_FTPReadFile ; --> _FTP_FileRead |
---|
104 | ;_FTPRenameFile ; --> _FTP_FileRename |
---|
105 | ;_FtpSetCurrentDir ; --> _FTP_DirSetCurrent |
---|
106 | ; =============================================================================================================================== |
---|
107 | |
---|
108 | ; #CURRENT# ===================================================================================================================== |
---|
109 | ;_FTP_Close |
---|
110 | ;_FTP_Command |
---|
111 | ;_FTP_Connect |
---|
112 | ;_FTP_DecodeInternetStatus |
---|
113 | ;_FTP_DirCreate |
---|
114 | ;_FTP_DirDelete |
---|
115 | ;_FTP_DirGetCurrent |
---|
116 | ;_FTP_DirPutContents |
---|
117 | ;_Ftp_DirSetCurrent |
---|
118 | ;_FTP_FileClose |
---|
119 | ;_FTP_FileDelete |
---|
120 | ;_FTP_FileGet |
---|
121 | ;_FTP_FileGetSize |
---|
122 | ;_FTP_FileOpen |
---|
123 | ;_FTP_FilePut |
---|
124 | ;_FTP_FileRead |
---|
125 | ;_FTP_FileRename |
---|
126 | ;_FTP_FileTimeLoHiToStr |
---|
127 | ;_FTP_FindFileClose |
---|
128 | ;_FTP_FindFileFirst |
---|
129 | ;_FTP_FindFileNext |
---|
130 | ;_FTP_GetLastResponseInfo |
---|
131 | ;_FTP_ListToArray |
---|
132 | ;_FTP_ListToArray2D |
---|
133 | ;_FTP_ListToArrayEx |
---|
134 | ;_FTP_Open |
---|
135 | ;_FTP_ProgressDownload |
---|
136 | ;_FTP_ProgressUpload |
---|
137 | ;_FTP_SetStatusCallback |
---|
138 | ; =============================================================================================================================== |
---|
139 | |
---|
140 | ; #INTERNAL_USE_ONLY#============================================================================================================ |
---|
141 | ;__FTP_ListToArray |
---|
142 | ;__FTP_Init |
---|
143 | ; =============================================================================================================================== |
---|
144 | |
---|
145 | ; #FUNCTION# ==================================================================================================================== |
---|
146 | ; Name...........: _FTP_Close |
---|
147 | ; Description ...: Closes the _FTP_Open session. |
---|
148 | ; Syntax.........: _FTP_Close($l_InternetSession) |
---|
149 | ; Parameters ....: $l_InternetSession - as returned by _FTP_Open(). |
---|
150 | ; Return values .: Success - 1 |
---|
151 | ; Failure - 0 |
---|
152 | ; Author ........: Wouter van Kesteren |
---|
153 | ; Modified.......: Beege |
---|
154 | ; Remarks .......: |
---|
155 | ; Related .......: _FTP_Open |
---|
156 | ; Link ..........: @@MsdnLink@@ InternetCloseHandle |
---|
157 | ; Example .......: Yes |
---|
158 | ; =============================================================================================================================== |
---|
159 | Func _FTP_Close($l_InternetSession) |
---|
160 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
161 | Local $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $l_InternetSession) |
---|
162 | If @error Or $ai_InternetCloseHandle[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
163 | |
---|
164 | If $__gbCallback_Set = True Then DllCallbackFree($__ghCallback_FTP) |
---|
165 | |
---|
166 | Return $ai_InternetCloseHandle[0] |
---|
167 | |
---|
168 | EndFunc ;==>_FTP_Close |
---|
169 | |
---|
170 | ; #FUNCTION# ==================================================================================================================== |
---|
171 | ; Name...........: _FTP_Command |
---|
172 | ; Description ...: Sends a command to an FTP server. |
---|
173 | ; Syntax.........: _FTP_Command($l_FTPSession, $s_FTPCommand[, $l_Flags = 0x00000001[, $l_ExpectResponse = 0[, $l_Context = 0]]]) |
---|
174 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
175 | ; $s_FTPCommand - Command string to send to FTP Server |
---|
176 | ; $l_Flags - Optional, $FTP_TRANSFER_TYPE_ASCII or $FTP_TRANSFER_TYPE_BINARY |
---|
177 | ; $l_ExpectResponse - Optional, Data socket for response in Async mode |
---|
178 | ; $l_Context - Optional, A pointer to a variable that contains an application-defined |
---|
179 | ; value used to identify the application context in callback operations |
---|
180 | ; The $l_ExpectResponse parameter must be set to TRUE for phFtpCommand to be filled. |
---|
181 | ; -> Parameter removed, is returned as @extended |
---|
182 | ; Return values .: Success - Returns an identifier. |
---|
183 | ; Failure - 0 and sets @ERROR |
---|
184 | ; Author ........: Bill Mezian |
---|
185 | ; Modified.......: |
---|
186 | ; Remarks .......: |
---|
187 | ; Command Examples: depends on server syntax. The following is for |
---|
188 | ; Binary transfer, ASCII transfer, Passive transfer mode (used with firewalls) |
---|
189 | ; 'type I' 'type A' 'pasv' |
---|
190 | ; Related .......: _FTP_Connect |
---|
191 | ; Link ..........: @@MsdnLink@@ FtpCommand |
---|
192 | ; Example .......: |
---|
193 | ; =============================================================================================================================== |
---|
194 | Func _FTP_Command($l_FTPSession, $s_FTPCommand, $l_Flags = $FTP_TRANSFER_TYPE_ASCII, $l_ExpectResponse = 0, $l_Context = 0) |
---|
195 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
196 | Local $ai_FTPCommand = DllCall($__ghWinInet_FTP, 'bool', 'FtpCommandW', 'handle', $l_FTPSession, 'bool', $l_ExpectResponse, 'dword', $l_Flags, 'wstr', $s_FTPCommand, 'dword_ptr', $l_Context, 'ptr*', 0) |
---|
197 | If @error Or $ai_FTPCommand[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
198 | |
---|
199 | Return SetError(0, $ai_FTPCommand[6], $ai_FTPCommand[0]) |
---|
200 | |
---|
201 | EndFunc ;==>_FTP_Command |
---|
202 | |
---|
203 | ; #FUNCTION# ==================================================================================================================== |
---|
204 | ; Name...........: _FTP_Connect |
---|
205 | ; Description ...: Connects to an FTP server. |
---|
206 | ; Syntax.........: _FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password[, $i_Passive = 0[, $i_ServerPort = 0[, $l_Service = 1[, $l_Flags = 0[, $l_Context = 0]]]]]) |
---|
207 | ; Parameters ....: $l_InternetSession - as returned by_FTP_Open(). |
---|
208 | ; $s_ServerName - Server name/ip. |
---|
209 | ; $s_Username - Username. |
---|
210 | ; $s_Password - Password. |
---|
211 | ; $i_Passive - Optional, Passive mode. |
---|
212 | ; $i_ServerPort - Optional, Server port ( 0 is default (21) ) |
---|
213 | ; $l_Service - Optional, I dont got a clue what this does. |
---|
214 | ; $l_Flags - Optional, Special flags. |
---|
215 | ; $l_Context - Optional, I dont got a clue what this does. |
---|
216 | ; Return values .: Success - Returns an identifier |
---|
217 | ; Failure - 0 and sets @ERROR |
---|
218 | ; Author ........: Wouter van Kesteren |
---|
219 | ; Modified.......: |
---|
220 | ; Remarks .......: |
---|
221 | ; Related .......: _FTP_Open |
---|
222 | ; Link ..........: @@MsdnLink@@ InternetConnect |
---|
223 | ; Example .......: Yes |
---|
224 | ; =============================================================================================================================== |
---|
225 | Func _FTP_Connect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_Passive = 0, $i_ServerPort = 0, $l_Service = $INTERNET_SERVICE_FTP, $l_Flags = 0, $l_Context = 0) |
---|
226 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
227 | If $i_Passive == 1 Then $l_Flags = BitOR($l_Flags, $INTERNET_FLAG_PASSIVE) |
---|
228 | Local $ai_InternetConnect = DllCall($__ghWinInet_FTP, 'hwnd', 'InternetConnectW', 'handle', $l_InternetSession, 'wstr', $s_ServerName, 'ushort', $i_ServerPort, 'wstr', $s_Username, 'wstr', $s_Password, 'dword', $l_Service, 'dword', $l_Flags, 'dword_ptr', $l_Context) |
---|
229 | If @error Or $ai_InternetConnect[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
230 | |
---|
231 | Return $ai_InternetConnect[0] |
---|
232 | |
---|
233 | EndFunc ;==>_FTP_Connect |
---|
234 | |
---|
235 | ; #FUNCTION# ==================================================================================================================== |
---|
236 | ; Name...........: _FTP_DecodeInternetStatus |
---|
237 | ; Description ...: Decode a received Internet Status. |
---|
238 | ; Syntax.........: _FTP_DecodeInternetStatus($dwInternetStatus) |
---|
239 | ; Parameters ....: $dwInternetStatus - Internet status. |
---|
240 | ; Return values .: Returns an string |
---|
241 | ; Author ........: Beege |
---|
242 | ; Modified.......: jpm |
---|
243 | ; Remarks .......: |
---|
244 | ; Related .......: _FTP_SetStatusCallback |
---|
245 | ; Link ..........: |
---|
246 | ; Example .......: Yes |
---|
247 | ; =============================================================================================================================== |
---|
248 | Func _FTP_DecodeInternetStatus($dwInternetStatus) |
---|
249 | Switch $dwInternetStatus |
---|
250 | Case $INTERNET_STATUS_CLOSING_CONNECTION |
---|
251 | Return 'Closing connection ...' |
---|
252 | |
---|
253 | Case $INTERNET_STATUS_CONNECTION_CLOSED |
---|
254 | Return 'Connection closed' |
---|
255 | |
---|
256 | Case $INTERNET_STATUS_CONNECTING_TO_SERVER |
---|
257 | Return 'Connecting to server ...' |
---|
258 | |
---|
259 | Case $INTERNET_STATUS_CONNECTED_TO_SERVER |
---|
260 | Return 'Connected to server' |
---|
261 | |
---|
262 | Case $INTERNET_STATUS_CTL_RESPONSE_RECEIVED |
---|
263 | Return 'CTL esponse received' |
---|
264 | |
---|
265 | Case $INTERNET_STATUS_INTERMEDIATE_RESPONSE |
---|
266 | Return 'Intermediate response' |
---|
267 | |
---|
268 | Case $INTERNET_STATUS_PREFETCH |
---|
269 | Return 'Prefetch' |
---|
270 | |
---|
271 | Case $INTERNET_STATUS_REDIRECT |
---|
272 | Return 'Redirect' |
---|
273 | |
---|
274 | Case $INTERNET_STATUS_REQUEST_COMPLETE |
---|
275 | Return 'Request complete' |
---|
276 | |
---|
277 | Case $INTERNET_STATUS_HANDLE_CREATED |
---|
278 | Return 'Handle created' |
---|
279 | |
---|
280 | Case $INTERNET_STATUS_HANDLE_CLOSING |
---|
281 | Return 'Handle closing ...' |
---|
282 | |
---|
283 | Case $INTERNET_STATUS_SENDING_REQUEST |
---|
284 | Return 'Sending request ...' |
---|
285 | |
---|
286 | Case $INTERNET_STATUS_REQUEST_SENT |
---|
287 | Return 'Request sent' |
---|
288 | |
---|
289 | Case $INTERNET_STATUS_RECEIVING_RESPONSE |
---|
290 | Return 'Receiving response ...' |
---|
291 | |
---|
292 | Case $INTERNET_STATUS_RESPONSE_RECEIVED |
---|
293 | Return 'Response received' |
---|
294 | |
---|
295 | Case $INTERNET_STATUS_STATE_CHANGE |
---|
296 | Return 'State change' |
---|
297 | |
---|
298 | Case $INTERNET_STATUS_RESOLVING_NAME |
---|
299 | Return 'Resolving name ...' |
---|
300 | |
---|
301 | Case $INTERNET_STATUS_NAME_RESOLVED |
---|
302 | Return 'Name resolved' |
---|
303 | Case Else |
---|
304 | Return 'UNKNOWN status = ' & $dwInternetStatus |
---|
305 | EndSwitch |
---|
306 | EndFunc ;==>_FTP_DecodeInternetStatus |
---|
307 | |
---|
308 | ; #FUNCTION# ==================================================================================================================== |
---|
309 | ; Name...........: _FTP_DirCreate |
---|
310 | ; Description ...: Makes an Directory on an FTP server. |
---|
311 | ; Syntax.........: _FTP_DirCreate($l_FTPSession, $s_Remote) |
---|
312 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
313 | ; $s_Remote - The Directory to Create. |
---|
314 | ; Return values .: Success - 1 |
---|
315 | ; Failure - 0 and sets @ERROR |
---|
316 | ; Author ........: Wouter van Kesteren |
---|
317 | ; Modified.......: |
---|
318 | ; Remarks .......: |
---|
319 | ; Related .......: _FTP_Connect |
---|
320 | ; Link ..........: @@MsdnLink@@ FtpCreateDirectory |
---|
321 | ; Example .......: |
---|
322 | ; =============================================================================================================================== |
---|
323 | Func _FTP_DirCreate($l_FTPSession, $s_Remote) |
---|
324 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
325 | Local $ai_FTPMakeDir = DllCall($__ghWinInet_FTP, 'bool', 'FtpCreateDirectoryW', 'handle', $l_FTPSession, 'wstr', $s_Remote) |
---|
326 | If @error Or $ai_FTPMakeDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
327 | |
---|
328 | Return $ai_FTPMakeDir[0] |
---|
329 | |
---|
330 | EndFunc ;==>_FTP_DirCreate |
---|
331 | |
---|
332 | ; #FUNCTION# ==================================================================================================================== |
---|
333 | ; Name...........: _FTP_DirDelete |
---|
334 | ; Description ...: Delete's an Directory on an FTP server. |
---|
335 | ; Syntax.........: _FTP_DirDelete($l_FTPSession, $s_Remote) |
---|
336 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
337 | ; $s_Remote - The Directory to be deleted. |
---|
338 | ; Return values .: Success - 1 |
---|
339 | ; Failure - 0 and sets @ERROR |
---|
340 | ; Author ........: Wouter van Kesteren |
---|
341 | ; Modified.......: |
---|
342 | ; Remarks .......: |
---|
343 | ; Related .......: _FTP_Connect |
---|
344 | ; Link ..........: @@MsdnLink@@ FtpRemoveDirectory |
---|
345 | ; Example .......: |
---|
346 | ; =============================================================================================================================== |
---|
347 | Func _FTP_DirDelete($l_FTPSession, $s_Remote) |
---|
348 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
349 | Local $ai_FTPDelDir = DllCall($__ghWinInet_FTP, 'bool', 'FtpRemoveDirectoryW', 'handle', $l_FTPSession, 'wstr', $s_Remote) |
---|
350 | If @error Or $ai_FTPDelDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
351 | |
---|
352 | Return $ai_FTPDelDir[0] |
---|
353 | |
---|
354 | EndFunc ;==>_FTP_DirDelete |
---|
355 | |
---|
356 | ; #FUNCTION# ==================================================================================================================== |
---|
357 | ; Name...........: _FTP_DirGetCurrent |
---|
358 | ; Description ...: Get Current Directory on an FTP server. |
---|
359 | ; Syntax.........: _FTP_DirGetCurrent($l_FTPSession) |
---|
360 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
361 | ; Return values .: Success - Directory Name |
---|
362 | ; Failure - 0 and sets @ERROR |
---|
363 | ; Author ........: Beast |
---|
364 | ; Modified.......: |
---|
365 | ; Remarks .......: |
---|
366 | ; Related .......: |
---|
367 | ; Link ..........: @@MsdnLink@@ FtpGetCurrentDirectory |
---|
368 | ; Example .......: |
---|
369 | ; =============================================================================================================================== |
---|
370 | Func _FTP_DirGetCurrent($l_FTPSession) |
---|
371 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
372 | Local $ai_FTPGetCurrentDir = DllCall($__ghWinInet_FTP, 'bool', 'FtpGetCurrentDirectoryW', 'handle', $l_FTPSession, 'wstr', "", 'dword*', 260) |
---|
373 | If @error Or $ai_FTPGetCurrentDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
374 | |
---|
375 | Return $ai_FTPGetCurrentDir[2] |
---|
376 | |
---|
377 | EndFunc ;==>_FTP_DirGetCurrent |
---|
378 | |
---|
379 | ; #FUNCTION# ==================================================================================================================== |
---|
380 | ; Name...........: _FTP_DirPutContents |
---|
381 | ; Description ...: Puts an folder on an FTP server. Recursivley if selected. |
---|
382 | ; Syntax.........: _FTP_DirPutContents($l_InternetSession, $s_LocalFolder, $s_RemoteFolder, $b_RecursivePut) |
---|
383 | ; Parameters ....: $l_InternetSession - as returned by _FTP_Connect(). |
---|
384 | ; $s_LocalFolder - The local folder i.e. "c:\temp". |
---|
385 | ; $s_RemoteFolder - The remote folder i.e. '/website/home'. |
---|
386 | ; $b_RecursivePut - Recurse through sub-dirs. 0=Non recursive, 1=Recursive |
---|
387 | ; $l_Context - Optional, see _FTP_Fileopen(). |
---|
388 | ; Return values .: Success - 1 |
---|
389 | ; Failure - 0 and sets @ERROR |
---|
390 | ; Author ........: Stumpii |
---|
391 | ; Modified.......: |
---|
392 | ; Remarks .......: |
---|
393 | ; Related .......: _FTP_Connect |
---|
394 | ; Link ..........: |
---|
395 | ; Example .......: |
---|
396 | ; =============================================================================================================================== |
---|
397 | Func _FTP_DirPutContents($l_InternetSession, $s_LocalFolder, $s_RemoteFolder, $b_RecursivePut, $l_Context = 0) |
---|
398 | |
---|
399 | If StringRight($s_LocalFolder, 1) == "\" Then $s_LocalFolder = StringTrimRight($s_LocalFolder, 1) |
---|
400 | ; Shows the filenames of all files in the current directory. |
---|
401 | Local $search = FileFindFirstFile($s_LocalFolder & "\*.*") |
---|
402 | |
---|
403 | ; Check if the search was successful |
---|
404 | If $search = -1 Then Return SetError(1, 0, 0) |
---|
405 | |
---|
406 | Local $File |
---|
407 | While 1 |
---|
408 | $File = FileFindNextFile($search) |
---|
409 | If @error Then ExitLoop |
---|
410 | If StringInStr(FileGetAttrib($s_LocalFolder & "\" & $File), "D") Then |
---|
411 | _FTP_DirCreate($l_InternetSession, $s_RemoteFolder & "/" & $File) |
---|
412 | If $b_RecursivePut Then |
---|
413 | _FTP_DirPutContents($l_InternetSession, $s_LocalFolder & "\" & $File, $s_RemoteFolder & "/" & $File, $b_RecursivePut, $l_Context) |
---|
414 | EndIf |
---|
415 | Else |
---|
416 | _FTP_FilePut($l_InternetSession, $s_LocalFolder & "\" & $File, $s_RemoteFolder & "/" & $File, 0, $l_Context) |
---|
417 | EndIf |
---|
418 | WEnd |
---|
419 | |
---|
420 | ; Close the search handle |
---|
421 | FileClose($search) |
---|
422 | Return 1 |
---|
423 | EndFunc ;==>_FTP_DirPutContents |
---|
424 | |
---|
425 | ; #FUNCTION# ==================================================================================================================== |
---|
426 | ; Name...........: _FTP_DirSetCurrent |
---|
427 | ; Description ...: Set Current Directory on an FTP server. |
---|
428 | ; Syntax.........: _FTP_DirSetCurrent($l_FTPSession, $s_Remote) |
---|
429 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
430 | ; $s_Remote - The Directory to be set. |
---|
431 | ; Return values .: Success - 1 |
---|
432 | ; Failure - 0 and sets @ERROR |
---|
433 | ; Author ........: Beast |
---|
434 | ; Modified.......: |
---|
435 | ; Remarks .......: |
---|
436 | ; Related .......: _FTP_Connect |
---|
437 | ; Link ..........: @@MsdnLink@@ FtpSetCurrentDirectory |
---|
438 | ; Example .......: |
---|
439 | ; =============================================================================================================================== |
---|
440 | Func _FTP_DirSetCurrent($l_FTPSession, $s_Remote) |
---|
441 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
442 | Local $ai_FTPSetCurrentDir = DllCall($__ghWinInet_FTP, 'bool', 'FtpSetCurrentDirectoryW', 'handle', $l_FTPSession, 'wstr', $s_Remote) |
---|
443 | If @error Or $ai_FTPSetCurrentDir[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
444 | |
---|
445 | Return $ai_FTPSetCurrentDir[0] |
---|
446 | |
---|
447 | EndFunc ;==>_FTP_DirSetCurrent |
---|
448 | |
---|
449 | ; #FUNCTION# ==================================================================================================================== |
---|
450 | ; Name...........: _FTP_FileClose |
---|
451 | ; Description ...: Closes the Handle returned by _FTP_FileOpen. |
---|
452 | ; Syntax.........: _FTP_FileClose($l_InternetSession) |
---|
453 | ; Parameters ....: $l_InternetSession - as returned by _FTP_FileOpen(). |
---|
454 | ; Return values .: Success - 1 |
---|
455 | ; Failure - 0 and sets @error =-1 |
---|
456 | ; Author ........: joeyb1275 |
---|
457 | ; Modified.......: Prog@ndy |
---|
458 | ; Remarks .......: found at http://www.autoitscript.com/forum/index.php?s=&showtopic=12473&view=findpost&p=331340 |
---|
459 | ; Related .......: |
---|
460 | ; Link ..........: @@MsdnLink@@ InternetCloseHandle |
---|
461 | ; Example .......: |
---|
462 | ; =============================================================================================================================== |
---|
463 | Func _FTP_FileClose($l_InternetSession) |
---|
464 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
465 | Local $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $l_InternetSession) |
---|
466 | If @error Or $ai_InternetCloseHandle[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
467 | |
---|
468 | Return $ai_InternetCloseHandle[0] |
---|
469 | |
---|
470 | EndFunc ;==>_FTP_FileClose |
---|
471 | |
---|
472 | ; #FUNCTION# ==================================================================================================================== |
---|
473 | ; Name...........: _FTP_FileDelete |
---|
474 | ; Description ...: Delete an file from an FTP server. |
---|
475 | ; Syntax.........: _FTP_FileDelete($l_FTPSession, $s_RemoteFile) |
---|
476 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
477 | ; $s_RemoteFile - The remote Location for the file. |
---|
478 | ; Return values .: Success - 1 |
---|
479 | ; Failure - 0 and sets @ERROR |
---|
480 | ; Author ........: Wouter van Kesteren |
---|
481 | ; Modified.......: |
---|
482 | ; Remarks .......: |
---|
483 | ; Related .......: |
---|
484 | ; Link ..........: @@MsdnLink@@ FtpDeleteFile |
---|
485 | ; Example .......: |
---|
486 | ; =============================================================================================================================== |
---|
487 | Func _FTP_FileDelete($l_FTPSession, $s_RemoteFile) |
---|
488 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
489 | Local $ai_FTPPutFile = DllCall($__ghWinInet_FTP, 'bool', 'FtpDeleteFileW', 'handle', $l_FTPSession, 'wstr', $s_RemoteFile) |
---|
490 | If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
491 | |
---|
492 | Return $ai_FTPPutFile[0] |
---|
493 | |
---|
494 | EndFunc ;==>_FTP_FileDelete |
---|
495 | |
---|
496 | ; #FUNCTION# ==================================================================================================================== |
---|
497 | ; Name...........: _FTP_FileGet |
---|
498 | ; Description ...: Get file from a FTP server. |
---|
499 | ; Syntax.........: _FTP_FileGet($l_FTPSession, $s_RemoteFile, $s_LocalFile[, $fFailIfExists = False,[ $dwFlagsAndAttributes = 0[, $l_Flags = 0[, $l_Context = 0]]]]) |
---|
500 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
501 | ; $s_RemoteFile - The remote Location for the file. |
---|
502 | ; $s_LocalFile - The local file. |
---|
503 | ; $fFailIfExists - Optional, True: do not overwrite existing (default = False) |
---|
504 | ; $dwFlagsAndAttributes - Optional, File attributes for the new file. |
---|
505 | ; $l_Flags - Optional, as in _FTP_FileOpen(). |
---|
506 | ; $l_Context - Optional, (Not Used) in case someone can use it. |
---|
507 | ; Return values .: Success - 1 |
---|
508 | ; Failure - 0 and sets @ERROR |
---|
509 | ; Author ........: Wouter van Kesteren |
---|
510 | ; Modified.......: |
---|
511 | ; Remarks .......: |
---|
512 | ; Related .......: |
---|
513 | ; Link ..........: @@MsdnLink@@ FtpGetFile |
---|
514 | ; Example .......: |
---|
515 | ; =============================================================================================================================== |
---|
516 | Func _FTP_FileGet($l_FTPSession, $s_RemoteFile, $s_LocalFile, $fFailIfExists = False, $dwFlagsAndAttributes = 0, $l_Flags = $FTP_TRANSFER_TYPE_UNKNOWN, $l_Context = 0) |
---|
517 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
518 | Local $ai_FTPGetFile = DllCall($__ghWinInet_FTP, 'bool', 'FtpGetFileW', 'handle', $l_FTPSession, 'wstr', $s_RemoteFile, 'wstr', $s_LocalFile, 'bool', $fFailIfExists, 'dword', $dwFlagsAndAttributes, 'dword', $l_Flags, 'dword_ptr', $l_Context) |
---|
519 | If @error Or $ai_FTPGetFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
520 | |
---|
521 | Return $ai_FTPGetFile[0] |
---|
522 | |
---|
523 | EndFunc ;==>_FTP_FileGet |
---|
524 | |
---|
525 | ; #FUNCTION# ==================================================================================================================== |
---|
526 | ; Name...........: _FTP_FileGetSize |
---|
527 | ; Description ...: Gets filesize of a file on the FTP server. |
---|
528 | ; Syntax.........: _FTP_FileGetSize($l_FTPSession, $s_FileName) |
---|
529 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
530 | ; $s_FileName - The file name. |
---|
531 | ; Return values .: Success - returns filesize as an uint64 |
---|
532 | ; Failure - sets @error non-zero |
---|
533 | ; Author ........: Joachim de Koning |
---|
534 | ; Modified.......: jpm |
---|
535 | ; Remarks .......: |
---|
536 | ; Related .......: |
---|
537 | ; Link ..........: @@MsdnLink@@ FtpGetFileSize |
---|
538 | ; Example .......: Yes |
---|
539 | ; =============================================================================================================================== |
---|
540 | Func _FTP_FileGetSize($l_FTPSession, $s_FileName) |
---|
541 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
542 | Local $ai_FTPGetSizeHandle = DllCall($__ghWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $l_FTPSession, 'wstr', $s_FileName, 'dword', $GENERIC_READ, 'dword', $INTERNET_FLAG_NO_CACHE_WRITE + $INTERNET_FLAG_TRANSFER_BINARY, 'dword_ptr', 0) |
---|
543 | If @error Or $ai_FTPGetSizeHandle[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
544 | |
---|
545 | Local $ai_FTPGetFileSize = DllCall($__ghWinInet_FTP, 'dword', 'FtpGetFileSize', 'handle', $ai_FTPGetSizeHandle[0], 'dword*', 0) |
---|
546 | If @error Or $ai_FTPGetFileSize[0] = 0 Then |
---|
547 | Local $lasterror = _WinAPI_GetLastError() |
---|
548 | DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FTPGetSizeHandle[0]) |
---|
549 | ; No need to test @error. |
---|
550 | |
---|
551 | Return SetError(-1, $lasterror, 0) |
---|
552 | EndIf |
---|
553 | |
---|
554 | DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_FTPGetSizeHandle[0]) |
---|
555 | ; No need to test @error. |
---|
556 | |
---|
557 | Return _WinAPI_MakeQWord($ai_FTPGetFileSize[0], $ai_FTPGetFileSize[2]) |
---|
558 | |
---|
559 | EndFunc ;==>_FTP_FileGetSize |
---|
560 | |
---|
561 | ; #FUNCTION# ==================================================================================================================== |
---|
562 | ; Name...........: _FTP_FileOpen |
---|
563 | ; Description ...: Initiates access to a remote file on an FTP server for reading or writing. |
---|
564 | ; Syntax.........: _FTP_FileOpen($hConnect, $lpszFileName[, $dwAccess = 0x80000000[, $dwFlags = 2[, $dwContext = 0]]]) |
---|
565 | ; Parameters ....: $hConnect - as returned by _FTP_Connect(). |
---|
566 | ; $lpszFileName - String of the ftp file to open. |
---|
567 | ; $dwAccess - Optional, GENERIC_READ or GENERIC_WRITE (Default is GENERIC_READ). |
---|
568 | ; $dwFlags - Optional, Settings for the transfer see notes below (Default is 2 for FTP_TRANSFER_TYPE_BINARY). |
---|
569 | ; $dwContext - Optional, (Not Used) See notes below. |
---|
570 | ; Return values .: Success - Returns the handle to ftp file for read with _FTP_FileRead() |
---|
571 | ; Failure - 0 and sets @error to non-zero |
---|
572 | ; Author ........: joeyb1275 |
---|
573 | ; Modified.......: Prog@ndy |
---|
574 | ; Remarks .......: found at http://www.autoitscript.com/forum/index.php?s=&showtopic=12473&view=findpost&p=331340 |
---|
575 | ;~ dwFlags |
---|
576 | ;~ [in] Conditions under which the transfers occur. The application should select one transfer type and any of |
---|
577 | ;~ the flags that indicate how the caching of the file will be controlled. |
---|
578 | ;~ The transfer type can be one of the following values. |
---|
579 | ;~ FTP_TRANSFER_TYPE_ASCII Transfers the file using FTP's ASCII (Type A) transfer method. Control and |
---|
580 | ;~ formatting information is converted to local equivalents. |
---|
581 | ;~ FTP_TRANSFER_TYPE_BINARY Transfers the file using FTP's Image (Type I) transfer method. The file is |
---|
582 | ;~ transferred exactly as it exists with no changes. This is the default transfer method. |
---|
583 | ;~ FTP_TRANSFER_TYPE_UNKNOWN Defaults to FTP_TRANSFER_TYPE_BINARY. |
---|
584 | ;~ INTERNET_FLAG_TRANSFER_ASCII Transfers the file as ASCII. |
---|
585 | ;~ INTERNET_FLAG_TRANSFER_BINARY Transfers the file as binary. |
---|
586 | ;~ The following values are used to control the caching of the file. The application can use one or more of these values. |
---|
587 | ;~ INTERNET_FLAG_HYPERLINK Forces a reload if there was no Expires time and no LastModified time returned from the server |
---|
588 | ;~ when determining whether to reload the item from the network. |
---|
589 | ;~ INTERNET_FLAG_NEED_FILE Causes a temporary file to be created if the file cannot be cached. |
---|
590 | ;~ INTERNET_FLAG_RELOAD Forces a download of the requested file, object, or directory listing from the origin server, |
---|
591 | ;~ not from the cache. |
---|
592 | ;~ INTERNET_FLAG_RESYNCHRONIZE Reloads HTTP resources if the resource has been modified since the last time it was |
---|
593 | ;~ downloaded. All FTP and Gopher resources are reloaded. |
---|
594 | ;~ dwContext |
---|
595 | ;~ [in] Pointer to a variable that contains the application-defined value that associates this search with any |
---|
596 | ;~ application data. This is only used if the application has already called _FTP_SetStatusCallback() to set |
---|
597 | ;~ up a status callback function. |
---|
598 | ; Related .......: _FTP_FileRead |
---|
599 | ; Link ..........: @@MsdnLink@@ FtpOpenFile |
---|
600 | ; Example .......: |
---|
601 | ; =============================================================================================================================== |
---|
602 | Func _FTP_FileOpen($hConnect, $lpszFileName, $dwAccess = $GENERIC_READ, $dwFlags = $INTERNET_FLAG_TRANSFER_BINARY, $dwContext = 0) |
---|
603 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
604 | Local $ai_ftpopenfile = DllCall($__ghWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $hConnect, 'wstr', $lpszFileName, 'dword', $dwAccess, 'dword', $dwFlags, 'dword_ptr', $dwContext) |
---|
605 | If @error Or $ai_ftpopenfile[0] == 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
606 | |
---|
607 | Return $ai_ftpopenfile[0] |
---|
608 | |
---|
609 | EndFunc ;==>_FTP_FileOpen |
---|
610 | |
---|
611 | ; #FUNCTION# ==================================================================================================================== |
---|
612 | ; Name...........: _FTP_FilePut |
---|
613 | ; Description ...: Puts an file on an FTP server. |
---|
614 | ; Syntax.........: _FTP_FilePut($l_FTPSession, $s_LocalFile, $s_RemoteFile[, $l_Flags = 0[, $l_Context = 0]]) |
---|
615 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
616 | ; $s_LocalFile - The local file. |
---|
617 | ; $s_RemoteFile - The remote Location for the file. |
---|
618 | ; $l_Flags - Optional, as in _FTP_FileOpen(). |
---|
619 | ; $l_Context - Optional, (Not Used) in case someone can use it. |
---|
620 | ; Return values .: Success - 1 |
---|
621 | ; Failure - 0 and sets @error to non-zero |
---|
622 | ; Author ........: Wouter van Kesteren |
---|
623 | ; Modified.......: |
---|
624 | ; Remarks .......: |
---|
625 | ; Related .......: |
---|
626 | ; Link ..........: @@MsdnLink@@ FtpPutFile |
---|
627 | ; Example .......: |
---|
628 | ; =============================================================================================================================== |
---|
629 | Func _FTP_FilePut($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0) |
---|
630 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
631 | Local $ai_FTPPutFile = DllCall($__ghWinInet_FTP, 'bool', 'FtpPutFileW', 'handle', $l_FTPSession, 'wstr', $s_LocalFile, 'wstr', $s_RemoteFile, 'dword', $l_Flags, 'dword_ptr', $l_Context) |
---|
632 | If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
633 | |
---|
634 | Return $ai_FTPPutFile[0] |
---|
635 | |
---|
636 | EndFunc ;==>_FTP_FilePut |
---|
637 | |
---|
638 | ; #FUNCTION# ==================================================================================================================== |
---|
639 | ; Name...........: _FTP_FileRead |
---|
640 | ; Description ...: Reads data from a handle opened by _FTP_FileOpen() |
---|
641 | ; Syntax.........: _FTP_FileRead($h_File, $dwNumberOfBytesToRead) |
---|
642 | ; Parameters ....: $h_File - Handle returned by _FTP_FileOpen() to the ftp file. |
---|
643 | ; $dwNumberOfBytesToRead - Number of bytes to read. |
---|
644 | ; Return values .: Success - Returns the binary/string read. |
---|
645 | ; Failure - 0 and Sets @error = -1 for end-of-file, @error to non-zero for other errors. |
---|
646 | ; Author ........: joeyb1275 |
---|
647 | ; Modified.......: Prog@ndy |
---|
648 | ; Remarks .......: found at http://www.autoitscript.com/forum/index.php?s=&showtopic=12473&view=findpost&p=331340 |
---|
649 | ; Related .......: |
---|
650 | ; Link ..........: @@MsdnLink@@ InternetReadFile |
---|
651 | ; Example .......: |
---|
652 | ; =============================================================================================================================== |
---|
653 | Func _FTP_FileRead($h_File, $dwNumberOfBytesToRead) |
---|
654 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
655 | Local $lpBuffer = DllStructCreate("byte[" & $dwNumberOfBytesToRead & "]") |
---|
656 | |
---|
657 | Local $ai_FTPReadFile = DllCall($__ghWinInet_FTP, 'bool', 'InternetReadFile', 'handle', $h_File, 'struct*', $lpBuffer, 'dword', $dwNumberOfBytesToRead, 'dword*', 0) ;LPDWORD lpdwNumberOfBytesRead |
---|
658 | If @error Then Return SetError(1, _WinAPI_GetLastError(), 0) |
---|
659 | |
---|
660 | Local $lpdwNumberOfBytesRead = $ai_FTPReadFile[4] |
---|
661 | If $lpdwNumberOfBytesRead == 0 And $ai_FTPReadFile[0] == 1 Then |
---|
662 | Return SetError(-1, 0, 0) |
---|
663 | ElseIf $ai_FTPReadFile[0] == 0 Then |
---|
664 | Return SetError(2, _WinAPI_GetLastError(), 0) |
---|
665 | EndIf |
---|
666 | |
---|
667 | Local $s_FileRead |
---|
668 | If $dwNumberOfBytesToRead > $lpdwNumberOfBytesRead Then |
---|
669 | $s_FileRead = BinaryMid(DllStructGetData($lpBuffer, 1), 1, $lpdwNumberOfBytesRead) ;index is omitted so the entire array is written into $s_FileRead as a BinaryString |
---|
670 | Else |
---|
671 | $s_FileRead = DllStructGetData($lpBuffer, 1) ;index is omitted so the entire array is written into $s_FileRead as a BinaryString |
---|
672 | EndIf |
---|
673 | |
---|
674 | Return SetError(0, $lpdwNumberOfBytesRead, $s_FileRead) |
---|
675 | |
---|
676 | EndFunc ;==>_FTP_FileRead |
---|
677 | |
---|
678 | ; #FUNCTION# ==================================================================================================================== |
---|
679 | ; Name...........: _FTP_FileRename |
---|
680 | ; Description ...: Renames an file on an FTP server. |
---|
681 | ; Syntax.........: _FTP_FileRename($l_FTPSession, $s_Existing, $s_New) |
---|
682 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
683 | ; $s_Existing - The old file name. |
---|
684 | ; $s_New - The new file name. |
---|
685 | ; Return values .: Success - 1 |
---|
686 | ; Failure - 0 and sets @error to non-zero |
---|
687 | ; Author ........: Wouter van Kesteren |
---|
688 | ; Modified.......: |
---|
689 | ; Remarks .......: |
---|
690 | ; Related .......: |
---|
691 | ; Link ..........: @@MsdnLink@@ FtpRenameFile |
---|
692 | ; Example .......: |
---|
693 | ; =============================================================================================================================== |
---|
694 | Func _FTP_FileRename($l_FTPSession, $s_Existing, $s_New) |
---|
695 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
696 | Local $ai_FTPRenameFile = DllCall($__ghWinInet_FTP, 'bool', 'FtpRenameFileW', 'handle', $l_FTPSession, 'wstr', $s_Existing, 'wstr', $s_New) |
---|
697 | If @error Or $ai_FTPRenameFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
698 | |
---|
699 | Return $ai_FTPRenameFile[0] |
---|
700 | |
---|
701 | EndFunc ;==>_FTP_FileRename |
---|
702 | |
---|
703 | ; #FUNCTION# ==================================================================================================================== |
---|
704 | ; Name...........: _FTP_FileTimeLoHiToStr |
---|
705 | ; Description ...: Get FileDateTime String |
---|
706 | ; Syntax.........: _FTP_FileTimeLoHiToStr($LoDWORD, $HiDWORD[, $bFmt = 0]) |
---|
707 | ; Parameters ....: $LoDWORD - FileTime Low |
---|
708 | ; $HiDWORD - File Time Hi |
---|
709 | ; $bFmt - Optional, 0 returns mm/dd/yyyy hh:mm:ss (Default) |
---|
710 | ; |1 returns yyyy/mm/dd hh:mm:ss |
---|
711 | ; Return values .: Success - DateTime according to $bFmt |
---|
712 | ; Failure - "" (empty String) |
---|
713 | ; Author ........: Prog@ndy |
---|
714 | ; Modified.......: |
---|
715 | ; Remarks .......: |
---|
716 | ; Related .......: |
---|
717 | ; Link ..........: |
---|
718 | ; Example .......: |
---|
719 | ; =============================================================================================================================== |
---|
720 | Func _FTP_FileTimeLoHiToStr($LoDWORD, $HiDWORD, $bFmt = 0) |
---|
721 | Local $tFileTime = DllStructCreate($tagFILETIME) |
---|
722 | If Not $LoDWORD And Not $HiDWORD Then Return SetError(1, 0, "") |
---|
723 | DllStructSetData($tFileTime, 1, $LoDWORD) |
---|
724 | DllStructSetData($tFileTime, 2, $HiDWORD) |
---|
725 | Local $date = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
726 | Return SetError(@error, @extended, $date) |
---|
727 | EndFunc ;==>_FTP_FileTimeLoHiToStr |
---|
728 | |
---|
729 | ; #FUNCTION# ==================================================================================================================== |
---|
730 | ; Name...........: _FTP_FindFileClose |
---|
731 | ; Description ...: Delete FindFile Handle. |
---|
732 | ; Syntax.........: _FTP_FindFileClose($h_Handle) |
---|
733 | ; Parameters ....: $h_Handle - Handle as return by _FTP_FindFileFirst(). |
---|
734 | ; Return values .: Success - 1 |
---|
735 | ; Failure - 0 and sets @error to non-zero |
---|
736 | ; Author ........: Dick Bronsdijk |
---|
737 | ; Modified.......: Prog@ndy, jpm |
---|
738 | ; Remarks .......: |
---|
739 | ; Related .......: |
---|
740 | ; Link ..........: @@MsdnLink@@ InternetCloseHandle |
---|
741 | ; Example .......: Yes |
---|
742 | ; =============================================================================================================================== |
---|
743 | Func _FTP_FindFileClose($h_Handle) |
---|
744 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
745 | Local $ai_FTPPutFile = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $h_Handle) |
---|
746 | If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), "") |
---|
747 | |
---|
748 | Return $ai_FTPPutFile[0] |
---|
749 | |
---|
750 | EndFunc ;==>_FTP_FindFileClose |
---|
751 | |
---|
752 | ; #FUNCTION# ==================================================================================================================== |
---|
753 | ; Name...........: _FTP_FindFileFirst |
---|
754 | ; Description ...: Find First File on an FTP server. |
---|
755 | ; Syntax.........: _FTP_FindFileFirst($l_FTPSession, $s_RemotePath, ByRef $h_Handle[, $l_Flags = 0[, $l_Context = 0]]) |
---|
756 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
757 | ; $s_RemotePath - path to be used when searching the file. |
---|
758 | ; $h_Handle - returns Handle to be used in _FTP_FindFileNext() or _FTP_FindFileClose(). |
---|
759 | ; $l_Flags - see remarks. |
---|
760 | ; $l_Context - (Not Used) in case someone can use it. |
---|
761 | ; Return values .: Success - an array, see remarks. |
---|
762 | ; Failure - 0 and sets @ERROR |
---|
763 | ; Author ........: Dick Bronsdijk |
---|
764 | ; Modified.......: Prog@ndy, jpm |
---|
765 | ; Remarks .......: If successfull a return array: |
---|
766 | ; [0] - Number of elements |
---|
767 | ; [1] - File Attributes |
---|
768 | ; [2] - Creation Time Low |
---|
769 | ; [3] - Creation Time Hi |
---|
770 | ; [4] - Access Time Low |
---|
771 | ; [5] - Access Time Hi |
---|
772 | ; [6] - Last Write Low |
---|
773 | ; [7] - Last Write Hi |
---|
774 | ; [8] - File Size High |
---|
775 | ; [9] - File Size Low |
---|
776 | ; [10] - File Name |
---|
777 | ; [11] - Altername |
---|
778 | ; $l_Flags can be a combination of $INTERNET_FLAG_HYPERLINK, $INTERNET_FLAG_NEED_FILE, $INTERNET_FLAG_NO_CACHE_WRITE, $INTERNET_FLAG_RELOAD, $INTERNET_FLAG_RESYNCHRONIZE |
---|
779 | ; Related .......: _FTP_FindFileNext, _FTP_FindFileClose |
---|
780 | ; Link ..........: @@MsdnLink@@ FtpFindFirstFile |
---|
781 | ; Example .......: Yes |
---|
782 | ; =============================================================================================================================== |
---|
783 | Func _FTP_FindFileFirst($l_FTPSession, $s_RemotePath, ByRef $h_Handle, $l_Flags = 0, $l_Context = 0) |
---|
784 | ;flags = 0 changed to $INTERNET_FLAG_TRANSFER_BINARY to see if stops hanging |
---|
785 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
786 | Local $l_DllStruct = DllStructCreate($tagWIN32_FIND_DATA) |
---|
787 | If @error Then Return SetError(-3, 0, "") |
---|
788 | |
---|
789 | Local $a_FTPFileList[1] |
---|
790 | $a_FTPFileList[0] = 0 |
---|
791 | |
---|
792 | Local $ai_FTPFirstFile = DllCall($__ghWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $l_FTPSession, 'wstr', $s_RemotePath, 'struct*', $l_DllStruct, 'dword', $l_Flags, 'dword_ptr', $l_Context) |
---|
793 | If @error Or $ai_FTPFirstFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), $ai_FTPFirstFile) |
---|
794 | |
---|
795 | $h_Handle = $ai_FTPFirstFile[0] |
---|
796 | |
---|
797 | Local $a_FTPFileList[12] |
---|
798 | $a_FTPFileList[0] = 11 |
---|
799 | $a_FTPFileList[1] = DllStructGetData($l_DllStruct, "dwFileAttributes") |
---|
800 | $a_FTPFileList[2] = DllStructGetData($l_DllStruct, "ftCreationTime", 1) |
---|
801 | $a_FTPFileList[3] = DllStructGetData($l_DllStruct, "ftCreationTime", 2) |
---|
802 | $a_FTPFileList[4] = DllStructGetData($l_DllStruct, "ftLastAccessTime", 1) |
---|
803 | $a_FTPFileList[5] = DllStructGetData($l_DllStruct, "ftLastAccessTime", 2) |
---|
804 | $a_FTPFileList[6] = DllStructGetData($l_DllStruct, "ftLastWriteTime", 1) |
---|
805 | $a_FTPFileList[7] = DllStructGetData($l_DllStruct, "ftLastWriteTime", 2) |
---|
806 | $a_FTPFileList[8] = DllStructGetData($l_DllStruct, "nFileSizeHigh") |
---|
807 | $a_FTPFileList[9] = DllStructGetData($l_DllStruct, "nFileSizeLow") |
---|
808 | $a_FTPFileList[10] = DllStructGetData($l_DllStruct, "cFileName") |
---|
809 | $a_FTPFileList[11] = DllStructGetData($l_DllStruct, "cAlternateFileName") |
---|
810 | |
---|
811 | Return $a_FTPFileList |
---|
812 | |
---|
813 | EndFunc ;==>_FTP_FindFileFirst |
---|
814 | |
---|
815 | ; #FUNCTION# ==================================================================================================================== |
---|
816 | ; Name...........: _FTP_FindFileNext |
---|
817 | ; Description ...: Find Next File on an FTP server. |
---|
818 | ; Syntax.........: _FTP_FindFileNext($h_Handle) |
---|
819 | ; Parameters ....: $h_Handle - as returned by _FTP_FindFileFirst(). |
---|
820 | ; Return values .: Success - an array, see remarks. |
---|
821 | ; Failure - 0 and sets @ERROR |
---|
822 | ; Author ........: Dick Bronsdijk |
---|
823 | ; Modified.......: Prog@ndy, jpm |
---|
824 | ; Remarks .......: If successfull a return array: |
---|
825 | ; [0] - Number of elements |
---|
826 | ; [1] - File Attributes |
---|
827 | ; [2] - Creation Time Low |
---|
828 | ; [3] - Creation Time Hi |
---|
829 | ; [4] - Access Time Low |
---|
830 | ; [5] - Access Time Hi |
---|
831 | ; [6] - Last Write Low |
---|
832 | ; [7] - Last Write Hi |
---|
833 | ; [8] - File Size High |
---|
834 | ; [9] - File Size Low |
---|
835 | ; [10] - File Name |
---|
836 | ; [11] - Altername |
---|
837 | ; Related .......: _FTP_FindFileFirst, _FTP_FindFileClose |
---|
838 | ; Link ..........: @@MsdnLink@@ InternetFindNextFile |
---|
839 | ; Example .......: Yes |
---|
840 | ; =============================================================================================================================== |
---|
841 | Func _FTP_FindFileNext($h_Handle) |
---|
842 | |
---|
843 | Local $l_DllStruct = DllStructCreate($tagWIN32_FIND_DATA) |
---|
844 | |
---|
845 | Local $a_FTPFileList[1] |
---|
846 | $a_FTPFileList[0] = 0 |
---|
847 | |
---|
848 | Local $ai_FTPPutFile = DllCall($__ghWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $h_Handle, 'struct*', $l_DllStruct) |
---|
849 | If @error Or $ai_FTPPutFile[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), $a_FTPFileList) |
---|
850 | |
---|
851 | Local $a_FTPFileList[12] |
---|
852 | $a_FTPFileList[0] = 11 |
---|
853 | $a_FTPFileList[1] = DllStructGetData($l_DllStruct, "dwFileAttributes") |
---|
854 | $a_FTPFileList[2] = DllStructGetData($l_DllStruct, "ftCreationTime", 1) |
---|
855 | $a_FTPFileList[3] = DllStructGetData($l_DllStruct, "ftCreationTime", 2) |
---|
856 | $a_FTPFileList[4] = DllStructGetData($l_DllStruct, "ftLastAccessTime", 1) |
---|
857 | $a_FTPFileList[5] = DllStructGetData($l_DllStruct, "ftLastAccessTime", 2) |
---|
858 | $a_FTPFileList[6] = DllStructGetData($l_DllStruct, "ftLastWriteTime", 1) |
---|
859 | $a_FTPFileList[7] = DllStructGetData($l_DllStruct, "ftLastWriteTime", 2) |
---|
860 | $a_FTPFileList[8] = DllStructGetData($l_DllStruct, "nFileSizeHigh") |
---|
861 | $a_FTPFileList[9] = DllStructGetData($l_DllStruct, "nFileSizeLow") |
---|
862 | $a_FTPFileList[10] = DllStructGetData($l_DllStruct, "cFileName") |
---|
863 | $a_FTPFileList[11] = DllStructGetData($l_DllStruct, "cAlternateFileName") |
---|
864 | |
---|
865 | Return $a_FTPFileList |
---|
866 | |
---|
867 | EndFunc ;==>_FTP_FindFileNext |
---|
868 | |
---|
869 | ; #FUNCTION# ==================================================================================================================== |
---|
870 | ; Name...........: _FTP_GetLastResponseInfo |
---|
871 | ; Description ...: Retrieves the last error description or server response on the thread calling this function. |
---|
872 | ; Syntax.........: _FTP_ListToArray(ByRef $dwError, ByRef $szMessage) |
---|
873 | ; Parameters ....: $dwError - returns an error message pertaining to the operation that failed. |
---|
874 | ; $szMessage - returns the error text. |
---|
875 | ; Return values .: Success - 1 |
---|
876 | ; Failure - 0 and set @error |
---|
877 | ; Author ........: jpm |
---|
878 | ; Modified.......: |
---|
879 | ; Remarks .......: |
---|
880 | ; Related .......: |
---|
881 | ; Link ..........: @@MsdnLink@@ InternetGetLastResponseInfo |
---|
882 | ; Example .......: |
---|
883 | ; =============================================================================================================================== |
---|
884 | Func _FTP_GetLastResponseInfo(ByRef $dwError, ByRef $szMessage) |
---|
885 | Local $ai_LastResponseInfo = DllCall($__ghWinInet_FTP, 'bool', 'InternetGetLastResponseInfoW', 'dword*', 0, 'wstr', "", 'dword*', 4096) |
---|
886 | If @error Or $ai_LastResponseInfo[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
887 | $dwError = $ai_LastResponseInfo[1] |
---|
888 | $szMessage = $ai_LastResponseInfo[2] |
---|
889 | Return $ai_LastResponseInfo[0] |
---|
890 | EndFunc ;==>_FTP_GetLastResponseInfo |
---|
891 | |
---|
892 | ; #FUNCTION# ==================================================================================================================== |
---|
893 | ; Name...........: _FTP_ListToArray |
---|
894 | ; Description ...: Get Filenames, Directories or Both of current remote directory. |
---|
895 | ; Syntax.........: _FTP_ListToArray($l_FTPSession[, $Return_Type = 0, $l_Flags = 0]]) |
---|
896 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
897 | ; $Return_type - Optional, 0 = Both Files and Directories, 1 = Directories, 2 = Files. |
---|
898 | ; $l_Flags - Optional, see _FTP_FindFileFirst(). |
---|
899 | ; $l_Context - Optional, see _FTP_Fileopen(). |
---|
900 | ; Return values .: Success - An array containing the names. Array[0] contain the number of found entries. |
---|
901 | ; Failure - Array[0] = 0 |
---|
902 | ; Author ........: Beast, Prog@ndy |
---|
903 | ; Modified.......: |
---|
904 | ; Remarks .......: |
---|
905 | ; Related .......: |
---|
906 | ; Link ..........: |
---|
907 | ; Example .......: Yes |
---|
908 | ; =============================================================================================================================== |
---|
909 | Func _FTP_ListToArray($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $l_Context = 0) |
---|
910 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
911 | Return __FTP_ListToArray($l_FTPSession, $Return_Type, $l_Flags, 0, 1, $l_Context) |
---|
912 | EndFunc ;==>_FTP_ListToArray |
---|
913 | |
---|
914 | ; #FUNCTION# ==================================================================================================================== |
---|
915 | ; Name...........: _FTP_ListToArray2D |
---|
916 | ; Description ...: Get Filenames and filesizes of current remote directory. |
---|
917 | ; Syntax.........: _FTP_ListToArray2D($l_FTPSession[, $Return_Type = 0[, $l_Flags = 0]]]) |
---|
918 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
919 | ; $Return_Type - Optional, 0 = Both Files and Directories, 1 = Directories, 2 = Files. |
---|
920 | ; $l_Flags - Optional, see _FTP_FindFileFirst(). |
---|
921 | ; $l_Context - Optional, see _FTP_Fileopen(). |
---|
922 | ; Return values .: Success - 2D Array with names and size. Array[0][0] contain the number of found entries. |
---|
923 | ; Failure - Array[0][0] = 0 |
---|
924 | ; Author ........: Prog@ndy |
---|
925 | ; Modified.......: jpm |
---|
926 | ; Remarks .......: Array[0][0] = number of found entries |
---|
927 | ; |
---|
928 | ; Array[x][0] Filename |
---|
929 | ; Array[x][1] Filesize |
---|
930 | ; Related .......: |
---|
931 | ; Link ..........: |
---|
932 | ; Example .......: Yes |
---|
933 | ; =============================================================================================================================== |
---|
934 | Func _FTP_ListToArray2D($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $l_Context = 0) |
---|
935 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
936 | Return __FTP_ListToArray($l_FTPSession, $Return_Type, $l_Flags, 0, 2, $l_Context) |
---|
937 | EndFunc ;==>_FTP_ListToArray2D |
---|
938 | |
---|
939 | ; #FUNCTION# ==================================================================================================================== |
---|
940 | ; Name...........: _FTP_ListToArrayEx |
---|
941 | ; Description ...: Get names, sizes, attributes aand times of files/dir of current remote directory. |
---|
942 | ; Syntax.........: _FTP_ListToArrayEx($l_FTPSession[, $Return_Type = 0[, $l_Flags = 0[, $b_Fmt = 1]]]) |
---|
943 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
944 | ; $Return_type - Optional, 0 = Both Files and Directories, 1 = Directories, 2 = Files. |
---|
945 | ; $l_Flags - Optional, see _FTP_FindFileFirst(). |
---|
946 | ; $b_Fmt - Optional, type on the date strings : 1 = yyyy/mm/dd, 0 = mm/dd/yyyy. |
---|
947 | ; $l_Context - Optional, see _FTP_Fileopen(). |
---|
948 | ; Return values .: Success - returns a 2D Array, see remarks. |
---|
949 | ; Failure - Array[0][0] = 0. |
---|
950 | ; Author ........: Beast, Prog@ndy |
---|
951 | ; Modified.......: jpm |
---|
952 | ; Remarks .......: Array[0][0] = number of found entries |
---|
953 | ; |
---|
954 | ; Array[x][0] Filename |
---|
955 | ; Array[x][1] Filesize |
---|
956 | ; Array[x][2] FileAttribute |
---|
957 | ; Array[x][3] File Modification datetime |
---|
958 | ; Array[x][4] File Creation datetime |
---|
959 | ; Array[x][5] File Access datetime |
---|
960 | ; Related .......: |
---|
961 | ; Link ..........: |
---|
962 | ; Example .......: Yes |
---|
963 | ; =============================================================================================================================== |
---|
964 | Func _FTP_ListToArrayEx($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $b_Fmt = 1, $l_Context = 0) |
---|
965 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
966 | Return __FTP_ListToArray($l_FTPSession, $Return_Type, $l_Flags, $b_Fmt, 6, $l_Context) |
---|
967 | EndFunc ;==>_FTP_ListToArrayEx |
---|
968 | |
---|
969 | ; #FUNCTION# ==================================================================================================================== |
---|
970 | ; Name...........: _FTP_Open |
---|
971 | ; Description ...: Opens an FTP session. |
---|
972 | ; Syntax.........: _FTP_Open($s_Agent[, $l_AccessType = 1[, $s_ProxyName = ''[, $s_ProxyBypass = ''[, $l_Flags = 0]]]] ) |
---|
973 | ; Parameters ....: $s_Agent - Random name. ( like "myftp" ). |
---|
974 | ; $l_AccessType - Set if proxy is used. |
---|
975 | ; $s_ProxyName - ProxyName. |
---|
976 | ; $s_ProxyBypass - ProxyByPasses's. |
---|
977 | ; $l_Flags - See remarks. |
---|
978 | ; Return values .: Success - Handle to internet session to be used in _FTP_Connect(). |
---|
979 | ; Failure - 0 and sets @ERROR |
---|
980 | ; Author ........: Wouter van Kesteren |
---|
981 | ; Modified.......: |
---|
982 | ; Remarks .......: Values for $l_AccessType |
---|
983 | ; $INTERNET_OPEN_TYPE_DIRECT -> no proxy |
---|
984 | ; $INTERNET_OPEN_TYPE_PRECONFIG -> Retrieves the proxy |
---|
985 | ; or direct configuration from the registry. |
---|
986 | ; $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY |
---|
987 | ; -> Retrieves the proxy or direct configuration |
---|
988 | ; from the registry and prevents the use of a |
---|
989 | ; startup Microsoft JScript or Internet Setup (INS) file. |
---|
990 | ; $INTERNET_OPEN_TYPE_PROXY -> Passes requests to the |
---|
991 | ; proxy unless a proxy bypass list is supplied |
---|
992 | ; and the name to be resolved bypasses the proxy. |
---|
993 | ; Then no proxy is used. |
---|
994 | ; Values for $l_Flags |
---|
995 | ; $INTERNET_FLAG_ASYNC -> Makes only asynchronous requests on handles descended |
---|
996 | ; from the handle returned from this function. |
---|
997 | ; $INTERNET_FLAG_FROM_CACHE -> Does not make network requests. |
---|
998 | ; All entities are returned from the cache. |
---|
999 | ; If the requested item is not in the cache, a suitable error, |
---|
1000 | ; such as ERROR_FILE_NOT_FOUND, is returned. |
---|
1001 | ; Related .......: |
---|
1002 | ; Link ..........: @@MsdnLink@@ InternetOpen |
---|
1003 | ; Example .......: Yes |
---|
1004 | ; =============================================================================================================================== |
---|
1005 | Func _FTP_Open($s_Agent, $l_AccessType = $INTERNET_OPEN_TYPE_DIRECT, $s_ProxyName = '', $s_ProxyBypass = '', $l_Flags = 0) |
---|
1006 | If $__ghWinInet_FTP = -1 Then __FTP_Init() |
---|
1007 | Local $ai_InternetOpen = DllCall($__ghWinInet_FTP, 'handle', 'InternetOpenW', 'wstr', $s_Agent, 'dword', $l_AccessType, _ |
---|
1008 | 'wstr', $s_ProxyName, 'wstr', $s_ProxyBypass, 'dword', $l_Flags) |
---|
1009 | If @error Or $ai_InternetOpen[0] = 0 Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
1010 | |
---|
1011 | Return $ai_InternetOpen[0] |
---|
1012 | |
---|
1013 | EndFunc ;==>_FTP_Open |
---|
1014 | |
---|
1015 | ; #FUNCTION# ==================================================================================================================== |
---|
1016 | ; Name...........: _FTP_ProgressDownload |
---|
1017 | ; Description ...: Downloads a file in Binary Mode and shows a Progress window or by Calling a User defined Function. |
---|
1018 | ; Syntax.........: _FTP_ProgressDownload($l_FTPSession, $s_LocalFile, $s_RemoteFile[, $FunctionToCall = ""]) |
---|
1019 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
1020 | ; $s_LocalFile - The local file to create. |
---|
1021 | ; $s_RemoteFile - The remote source file. |
---|
1022 | ; $FunctionToCall - [Optional] A function which can update a Progressbar and |
---|
1023 | ; react on UserInput like Click on Abort or Close App. |
---|
1024 | ; (More info in the end of this comment) |
---|
1025 | ; Return values .: Success - 1 |
---|
1026 | ; Error: 0 and @error: |
---|
1027 | ; -1 -> Local file couldn't be created |
---|
1028 | ; -2 -> Unable to get RemoteFile size |
---|
1029 | ; -3 -> Open RemoteFile failed |
---|
1030 | ; -4 -> Read from Remotefile failed |
---|
1031 | ; -5 -> Close RemoteFile failed |
---|
1032 | ; -6 -> Download aborted by PercentageFunc, Return of Called Function |
---|
1033 | ; -7 -> Local file write failed |
---|
1034 | ; Author ........: limette, Prog@ndy |
---|
1035 | ; Modified.......: jchd |
---|
1036 | ; Remarks .......: |
---|
1037 | ; Information about $FunctionToCall: |
---|
1038 | ; Parameter: $Percentage - The Percentage of Progress |
---|
1039 | ; Return Values: Continue Download - 1 |
---|
1040 | ; Abort Download - 0 Or negative |
---|
1041 | ; These Return Values are returned by _FTP_ProgressDownload(), too, |
---|
1042 | ; so you can react on different Actions like Aborting by User, closing App or TimeOut of whatever |
---|
1043 | ;~ Examples: |
---|
1044 | ;~ Func _UpdateProgress($Percentage) |
---|
1045 | ;~ ProgressSet($percent,$percent &"%") |
---|
1046 | ;~ If _IsPressed("77") Then Return 0 ; Abort on F8 |
---|
1047 | ;~ Return 1 ; bei 1 Fortsetzten |
---|
1048 | ;~ Endfunc |
---|
1049 | ; |
---|
1050 | ;~ Func _UpdateProgress($Percentage) |
---|
1051 | ;~ GUICtrlSetData($ProgressBarCtrl,$percent) |
---|
1052 | ;~ Switch GUIGetMsg() |
---|
1053 | ;~ Case $GUI_EVENT_CLOSE |
---|
1054 | ;~ Return -1 ; _FTP_DownloadProgress Aborts with -1, so you can exit you app afterwards |
---|
1055 | ;~ Case $Btn_Cancel |
---|
1056 | ;~ Return 0 ; Just Cancel, without special Return value |
---|
1057 | ;~ EndSwitch |
---|
1058 | ;~ Return 1 ; Otherwise contine Download |
---|
1059 | ;~ Endfunc |
---|
1060 | ; Related .......: |
---|
1061 | ; Link ..........: |
---|
1062 | ; Example .......: |
---|
1063 | ; =============================================================================================================================== |
---|
1064 | Func _FTP_ProgressDownload($l_FTPSession, $s_LocalFile, $s_RemoteFile, $FunctionToCall = "") |
---|
1065 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
1066 | |
---|
1067 | Local $fhandle = FileOpen($s_LocalFile, 18) |
---|
1068 | If $fhandle < 0 Then Return SetError(-1, 0, 0) |
---|
1069 | |
---|
1070 | Local $ai_ftpopenfile = DllCall($__ghWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $l_FTPSession, 'wstr', $s_RemoteFile, 'dword', $GENERIC_READ, 'dword', $FTP_TRANSFER_TYPE_BINARY, 'dword_ptr', 0) |
---|
1071 | If @error Or $ai_ftpopenfile[0] = 0 Then Return SetError(-3, _WinAPI_GetLastError(), 0) |
---|
1072 | |
---|
1073 | Local $ai_FTPGetFileSize = DllCall($__ghWinInet_FTP, 'dword', 'FtpGetFileSize', 'handle', $ai_ftpopenfile[0], 'dword*', 0) |
---|
1074 | If @error Then Return SetError(-2, _WinAPI_GetLastError(), 0) |
---|
1075 | |
---|
1076 | If $FunctionToCall = "" Then ProgressOn("FTP Download", "Downloading " & $s_LocalFile) |
---|
1077 | |
---|
1078 | Local $glen = _WinAPI_MakeQWord($ai_FTPGetFileSize[0], $ai_FTPGetFileSize[2]) ;FileGetSize($s_RemoteFile) |
---|
1079 | Local Const $ChunkSize = 256 * 1024 |
---|
1080 | Local $last = Mod($glen, $ChunkSize) |
---|
1081 | |
---|
1082 | Local $parts = Ceiling($glen / $ChunkSize) |
---|
1083 | Local $buffer = DllStructCreate("byte[" & $ChunkSize & "]") |
---|
1084 | |
---|
1085 | Local $ai_InternetCloseHandle, $ai_FTPread, $out, $ret, $lasterror |
---|
1086 | Local $x = $ChunkSize |
---|
1087 | Local $done = 0 |
---|
1088 | For $i = 1 To $parts |
---|
1089 | If $i = $parts And $last > 0 Then |
---|
1090 | $x = $last |
---|
1091 | EndIf |
---|
1092 | |
---|
1093 | $ai_FTPread = DllCall($__ghWinInet_FTP, 'bool', 'InternetReadFile', 'handle', $ai_ftpopenfile[0], 'struct*', $buffer, 'dword', $x, 'dword*', $out) |
---|
1094 | If @error Or $ai_FTPread[0] = 0 Then |
---|
1095 | $lasterror = _WinAPI_GetLastError() |
---|
1096 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1097 | ; No need to test @error. |
---|
1098 | FileClose($fhandle) |
---|
1099 | If $FunctionToCall = "" Then ProgressOff() |
---|
1100 | Return SetError(-4, $lasterror, 0) |
---|
1101 | EndIf |
---|
1102 | $ret = FileWrite($fhandle, BinaryMid(DllStructGetData($buffer, 1), 1, $ai_FTPread[4])) |
---|
1103 | If Not $ret Then |
---|
1104 | $lasterror = _WinAPI_GetLastError() |
---|
1105 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1106 | ; No need to test @error. |
---|
1107 | FileClose($fhandle) |
---|
1108 | FileDelete($s_LocalFile) |
---|
1109 | If $FunctionToCall = "" Then ProgressOff() |
---|
1110 | Return SetError(-7, $lasterror, 0) |
---|
1111 | EndIf |
---|
1112 | $done += $ai_FTPread[4] |
---|
1113 | |
---|
1114 | If $FunctionToCall = "" Then |
---|
1115 | ProgressSet(($done / $glen) * 100) |
---|
1116 | Else |
---|
1117 | $ret = Call($FunctionToCall, ($done / $glen) * 100) |
---|
1118 | If $ret <= 0 Then |
---|
1119 | $lasterror = @error |
---|
1120 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1121 | ; No need to test @error. |
---|
1122 | FileClose($fhandle) |
---|
1123 | FileDelete($s_LocalFile) |
---|
1124 | If $FunctionToCall = "" Then ProgressOff() |
---|
1125 | Return SetError(-6, $lasterror, $ret) |
---|
1126 | EndIf |
---|
1127 | EndIf |
---|
1128 | Sleep(10) |
---|
1129 | Next |
---|
1130 | |
---|
1131 | FileClose($fhandle) |
---|
1132 | |
---|
1133 | If $FunctionToCall = "" Then ProgressOff() |
---|
1134 | |
---|
1135 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1136 | If @error Or $ai_InternetCloseHandle[0] = 0 Then |
---|
1137 | Return SetError(-5, _WinAPI_GetLastError(), 0) |
---|
1138 | EndIf |
---|
1139 | |
---|
1140 | Return 1 |
---|
1141 | EndFunc ;==>_FTP_ProgressDownload |
---|
1142 | |
---|
1143 | ; #FUNCTION# ==================================================================================================================== |
---|
1144 | ; Name...........: _FTP_ProgressUpload |
---|
1145 | ; Description ...: Uploads a file in Binary Mode and shows a Progress window or by Calling a User defined Function. |
---|
1146 | ; Syntax.........: _FTP_ProgressUpload($l_FTPSession, $s_LocalFile, $s_RemoteFile[, $FunctionToCall = ""]) |
---|
1147 | ; Parameters ....: $l_FTPSession - as returned by _FTP_Connect(). |
---|
1148 | ; $s_LocalFile - The local file. |
---|
1149 | ; $s_RemoteFile - The remote Location for the file. |
---|
1150 | ; $FunctionToCall - [Optional] A function which can update a Progressbar and |
---|
1151 | ; react on UserInput like Click on Abort or Close App. |
---|
1152 | ; (More info in the end of this comment) |
---|
1153 | ; Return values .: Success: 1 |
---|
1154 | ; Error: 0 and @error: |
---|
1155 | ; -1 -> Local file couldn't be opened |
---|
1156 | ; -3 -> Create File failed |
---|
1157 | ; -4 -> Write to file failed |
---|
1158 | ; -5 -> Close File failed |
---|
1159 | ; -6 -> Download aborted by PercentageFunc, Return of Called Function |
---|
1160 | ; Author ........: limette, Prog@ndy |
---|
1161 | ; Modified.......: jchd |
---|
1162 | ; Remarks .......: |
---|
1163 | ; Information about $FunctionToCall: |
---|
1164 | ; Parameter: $Percentage - The Percentage of Progress |
---|
1165 | ; Return Values: Continue Download - 1 |
---|
1166 | ; Abort Download - 0 Or negative |
---|
1167 | ; These Return Values are returned by _FTP_UploadProgress, too, |
---|
1168 | ; so you can react on different Actions like Aborting by User, closing App or TimeOut of whatever |
---|
1169 | ;~ Examples: |
---|
1170 | ;~ Func _UpdateProgress($Percentage) |
---|
1171 | ;~ ProgressSet($percent,$percent &"%") |
---|
1172 | ;~ If _IsPressed("77") Then Return 0 ; Abort on F8 |
---|
1173 | ;~ Return 1 ; bei 1 Fortsetzten |
---|
1174 | ;~ Endfunc |
---|
1175 | ; |
---|
1176 | ;~ Func _UpdateProgress($Percentage) |
---|
1177 | ;~ GUICtrlSetData($ProgressBarCtrl,$percent) |
---|
1178 | ;~ Switch GUIGetMsg() |
---|
1179 | ;~ Case $GUI_EVENT_CLOSE |
---|
1180 | ;~ Return -1 ; _FTP_UploadProgress Aborts with -1, so you can exit you app afterwards |
---|
1181 | ;~ Case $Btn_Cancel |
---|
1182 | ;~ Return 0 ; Just Cancel, without special Return value |
---|
1183 | ;~ EndSwitch |
---|
1184 | ;~ Return 1 ; Otherwise contine Upload |
---|
1185 | ;~ Endfunc |
---|
1186 | ; Related .......: |
---|
1187 | ; Link ..........: @@MsdnLink@@ FtpOpenFile |
---|
1188 | ; Example .......: |
---|
1189 | ; =============================================================================================================================== |
---|
1190 | Func _FTP_ProgressUpload($l_FTPSession, $s_LocalFile, $s_RemoteFile, $FunctionToCall = "") |
---|
1191 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
1192 | |
---|
1193 | Local $fhandle = FileOpen($s_LocalFile, 16) |
---|
1194 | If @error Then Return SetError(-1, _WinAPI_GetLastError(), 0) |
---|
1195 | |
---|
1196 | Local $ai_ftpopenfile = DllCall($__ghWinInet_FTP, 'handle', 'FtpOpenFileW', 'handle', $l_FTPSession, 'wstr', $s_RemoteFile, 'dword', $GENERIC_WRITE, 'dword', $FTP_TRANSFER_TYPE_BINARY, 'dword_ptr', 0) |
---|
1197 | If @error Or $ai_ftpopenfile[0] = 0 Then Return SetError(-3, _WinAPI_GetLastError(), 0) |
---|
1198 | |
---|
1199 | If $FunctionToCall = "" Then ProgressOn("FTP Upload", "Uploading " & $s_LocalFile) |
---|
1200 | |
---|
1201 | Local $glen = FileGetSize($s_LocalFile) |
---|
1202 | Local Const $ChunkSize = 256 * 1024 |
---|
1203 | Local $last = Mod($glen, $ChunkSize) |
---|
1204 | |
---|
1205 | Local $parts = Ceiling($glen / $ChunkSize) |
---|
1206 | Local $buffer = DllStructCreate("byte[" & $ChunkSize & "]") |
---|
1207 | |
---|
1208 | Local $ai_InternetCloseHandle, $ai_ftpwrite, $out, $ret, $lasterror |
---|
1209 | Local $x = $ChunkSize |
---|
1210 | Local $done = 0 |
---|
1211 | For $i = 1 To $parts |
---|
1212 | If $i = $parts And $last > 0 Then |
---|
1213 | $x = $last |
---|
1214 | EndIf |
---|
1215 | DllStructSetData($buffer, 1, FileRead($fhandle, $x)) |
---|
1216 | |
---|
1217 | $ai_ftpwrite = DllCall($__ghWinInet_FTP, 'bool', 'InternetWriteFile', 'handle', $ai_ftpopenfile[0], 'struct*', $buffer, 'dword', $x, 'dword*', $out) |
---|
1218 | If @error Or $ai_ftpwrite[0] = 0 Then |
---|
1219 | $lasterror = _WinAPI_GetLastError() |
---|
1220 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1221 | ; No need to test @error. |
---|
1222 | FileClose($fhandle) |
---|
1223 | |
---|
1224 | If $FunctionToCall = "" Then ProgressOff() |
---|
1225 | Return SetError(-4, $lasterror, 0) |
---|
1226 | EndIf |
---|
1227 | $done += $x |
---|
1228 | |
---|
1229 | If $FunctionToCall = "" Then |
---|
1230 | ProgressSet(($done / $glen) * 100) |
---|
1231 | Else |
---|
1232 | $ret = Call($FunctionToCall, ($done / $glen) * 100) |
---|
1233 | If $ret <= 0 Then |
---|
1234 | $lasterror = @error |
---|
1235 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1236 | ; No need to test @error. |
---|
1237 | DllCall($__ghWinInet_FTP, 'bool', 'FtpDeleteFileW', 'handle', $l_FTPSession, 'wstr', $s_RemoteFile) |
---|
1238 | ; No need to test @error. |
---|
1239 | FileClose($fhandle) |
---|
1240 | If $FunctionToCall = "" Then ProgressOff() |
---|
1241 | Return SetError(-6, $lasterror, $ret) |
---|
1242 | EndIf |
---|
1243 | EndIf |
---|
1244 | Sleep(10) |
---|
1245 | Next |
---|
1246 | |
---|
1247 | FileClose($fhandle) |
---|
1248 | |
---|
1249 | If $FunctionToCall = "" Then ProgressOff() |
---|
1250 | |
---|
1251 | $ai_InternetCloseHandle = DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $ai_ftpopenfile[0]) |
---|
1252 | ; No need to test @error. |
---|
1253 | If @error Or $ai_InternetCloseHandle[0] = 0 Then Return SetError(-5, _WinAPI_GetLastError(), 0) |
---|
1254 | |
---|
1255 | Return 1 |
---|
1256 | EndFunc ;==>_FTP_ProgressUpload |
---|
1257 | |
---|
1258 | ;FUNCTION# ==================================================================================================================== |
---|
1259 | ; Name...........: _FTP_SetStatusCallback |
---|
1260 | ; Description ...: Registers callback function that WinINet functions can call as progress is made during an operation. |
---|
1261 | ; Syntax.........: _InternetSetStatusCallback($l_InternetSession, $sFunctionName) |
---|
1262 | ; Parameters ....: $l_InternetSession - as returned by _FTP_Open(). |
---|
1263 | ; $sFunctionName - The name of the User Defined Function to call |
---|
1264 | ; Return values .: Success - Pointer to callback function |
---|
1265 | ; Failure - 0 and Set @error |
---|
1266 | ; Author ........: Beege |
---|
1267 | ; Modified.......: jpm |
---|
1268 | ; Remarks .......: |
---|
1269 | ; Related .......: _FTP_DecodeInternetStatus |
---|
1270 | ; Link ..........: @@MsdnLink@@ InternetSetStatusCallback |
---|
1271 | ; Example .......: Yes |
---|
1272 | ; =============================================================================================================================== |
---|
1273 | Func _FTP_SetStatusCallback($l_InternetSession, $sFunctionName) |
---|
1274 | If $__ghWinInet_FTP = -1 Then Return SetError(-2, 0, 0) |
---|
1275 | |
---|
1276 | Local $CallBack_Register = DllCallbackRegister($sFunctionName, "none", "ptr;ptr;dword;ptr;dword") |
---|
1277 | If Not $CallBack_Register Then Return SetError(-1, 0, 0) |
---|
1278 | |
---|
1279 | Local $ah_CallBackFunction = DllCall('wininet.dll', "ptr", "InternetSetStatusCallback", "ptr", $l_InternetSession, "ulong_ptr", DllCallbackGetPtr($CallBack_Register)) |
---|
1280 | If @error Then Return SetError(-3, 0, 0) |
---|
1281 | If $ah_CallBackFunction[0] = Ptr(-1) Then Return SetError(-4, 0, 0) ; INTERNET_INVALID_STATUS_CALLBACK |
---|
1282 | |
---|
1283 | $__gbCallback_Set = True |
---|
1284 | $__ghCallback_FTP = $CallBack_Register |
---|
1285 | Return $ah_CallBackFunction[1] |
---|
1286 | EndFunc ;==>_FTP_SetStatusCallback |
---|
1287 | |
---|
1288 | ; #INTERNAL_USE_ONLY# =========================================================================================================== |
---|
1289 | ; Name...........: __FTP_ListToArray |
---|
1290 | ; Description ...: |
---|
1291 | ; Syntax.........: __FTP_ListToArray($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $bFmt = 1, $ArrayCount = 6) |
---|
1292 | ; Parameters ....: |
---|
1293 | ; Return values .: an 2D array with the requested info defined by $ArrayCount |
---|
1294 | ; [0] Filename |
---|
1295 | ; [1] Filesize |
---|
1296 | ; [2] FileAttribute |
---|
1297 | ; [3] File Modification time |
---|
1298 | ; [4] File Creation time |
---|
1299 | ; [5] File Access time |
---|
1300 | ; Author ........: Beast, Prog@ndy |
---|
1301 | ; Modified.......: jpm (to be use by external UDFs) |
---|
1302 | ; Remarks .......: |
---|
1303 | ; Related .......: |
---|
1304 | ; Link ..........: |
---|
1305 | ; Example .......: |
---|
1306 | ; =============================================================================================================================== |
---|
1307 | Func __FTP_ListToArray($l_FTPSession, $Return_Type = 0, $l_Flags = 0, $bFmt = 1, $ArrayCount = 6, $l_Context = 0) |
---|
1308 | Local $tWIN32_FIND_DATA, $tFileTime, $IsDir, $callFindNext |
---|
1309 | Local $DirectoryIndex = 0, $FileIndex = 0 |
---|
1310 | |
---|
1311 | If $ArrayCount = 1 Then |
---|
1312 | Local $FileArray[1], $DirectoryArray[1] |
---|
1313 | Else |
---|
1314 | Local $FileArray[1][$ArrayCount], $DirectoryArray[1][$ArrayCount] |
---|
1315 | EndIf |
---|
1316 | |
---|
1317 | If $Return_Type < 0 Or $Return_Type > 2 Then |
---|
1318 | $FileArray[0][0] = 0 |
---|
1319 | Return SetError(1, 0, $FileArray) |
---|
1320 | EndIf |
---|
1321 | |
---|
1322 | ;~ 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];" |
---|
1323 | $tWIN32_FIND_DATA = DllStructCreate($tagWIN32_FIND_DATA) |
---|
1324 | Local $callFindFirst = DllCall($__ghWinInet_FTP, 'handle', 'FtpFindFirstFileW', 'handle', $l_FTPSession, 'wstr', "", 'struct*', $tWIN32_FIND_DATA, 'dword', $l_Flags, 'dword_ptr', $l_Context) |
---|
1325 | If @error Or Not $callFindFirst[0] Then Return SetError(1, _WinAPI_GetLastError(), 0) |
---|
1326 | |
---|
1327 | Do |
---|
1328 | $IsDir = BitAND(DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes"), $FILE_ATTRIBUTE_DIRECTORY) = $FILE_ATTRIBUTE_DIRECTORY |
---|
1329 | If $IsDir And ($Return_Type <> 2) Then |
---|
1330 | $DirectoryIndex += 1 |
---|
1331 | If $ArrayCount = 1 Then |
---|
1332 | If UBound($DirectoryArray) < $DirectoryIndex + 1 Then ReDim $DirectoryArray[$DirectoryIndex * 2] |
---|
1333 | $DirectoryArray[$DirectoryIndex] = DllStructGetData($tWIN32_FIND_DATA, "cFileName") |
---|
1334 | Else |
---|
1335 | If UBound($DirectoryArray) < $DirectoryIndex + 1 Then ReDim $DirectoryArray[$DirectoryIndex * 2][$ArrayCount] |
---|
1336 | $DirectoryArray[$DirectoryIndex][0] = DllStructGetData($tWIN32_FIND_DATA, "cFileName") |
---|
1337 | |
---|
1338 | $DirectoryArray[$DirectoryIndex][1] = _WinAPI_MakeQWord(DllStructGetData($tWIN32_FIND_DATA, "nFileSizeLow"), DllStructGetData($tWIN32_FIND_DATA, "nFileSizeHigh")) |
---|
1339 | If $ArrayCount = 6 Then |
---|
1340 | $DirectoryArray[$DirectoryIndex][2] = DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes") |
---|
1341 | |
---|
1342 | $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastWriteTime")) |
---|
1343 | $DirectoryArray[$DirectoryIndex][3] = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
1344 | $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftCreationTime")) |
---|
1345 | $DirectoryArray[$DirectoryIndex][4] = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
1346 | $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastAccessTime")) |
---|
1347 | $DirectoryArray[$DirectoryIndex][5] = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
1348 | EndIf |
---|
1349 | EndIf |
---|
1350 | ElseIf Not $IsDir And $Return_Type <> 1 Then |
---|
1351 | $FileIndex += 1 |
---|
1352 | If $ArrayCount = 1 Then |
---|
1353 | If UBound($FileArray) < $FileIndex + 1 Then ReDim $FileArray[$FileIndex * 2] |
---|
1354 | $FileArray[$FileIndex] = DllStructGetData($tWIN32_FIND_DATA, "cFileName") |
---|
1355 | Else |
---|
1356 | If UBound($FileArray) < $FileIndex + 1 Then ReDim $FileArray[$FileIndex * 2][$ArrayCount] |
---|
1357 | $FileArray[$FileIndex][0] = DllStructGetData($tWIN32_FIND_DATA, "cFileName") |
---|
1358 | |
---|
1359 | $FileArray[$FileIndex][1] = _WinAPI_MakeQWord(DllStructGetData($tWIN32_FIND_DATA, "nFileSizeLow"), DllStructGetData($tWIN32_FIND_DATA, "nFileSizeHigh")) |
---|
1360 | If $ArrayCount = 6 Then |
---|
1361 | $FileArray[$FileIndex][2] = DllStructGetData($tWIN32_FIND_DATA, "dwFileAttributes") |
---|
1362 | |
---|
1363 | $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastWriteTime")) |
---|
1364 | $FileArray[$FileIndex][3] = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
1365 | $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftCreationTime")) |
---|
1366 | $FileArray[$FileIndex][4] = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
1367 | $tFileTime = DllStructCreate($tagFILETIME, DllStructGetPtr($tWIN32_FIND_DATA, "ftLastAccessTime")) |
---|
1368 | $FileArray[$FileIndex][5] = _Date_Time_FileTimeToStr($tFileTime, $bFmt) |
---|
1369 | EndIf |
---|
1370 | EndIf |
---|
1371 | EndIf |
---|
1372 | |
---|
1373 | $callFindNext = DllCall($__ghWinInet_FTP, 'bool', 'InternetFindNextFileW', 'handle', $callFindFirst[0], 'struct*', $tWIN32_FIND_DATA) |
---|
1374 | If @error Then Return SetError(2, _WinAPI_GetLastError(), 0) |
---|
1375 | Until Not $callFindNext[0] |
---|
1376 | |
---|
1377 | DllCall($__ghWinInet_FTP, 'bool', 'InternetCloseHandle', 'handle', $callFindFirst[0]) |
---|
1378 | ; No need to test @error. |
---|
1379 | |
---|
1380 | If $ArrayCount = 1 Then |
---|
1381 | $DirectoryArray[0] = $DirectoryIndex |
---|
1382 | $FileArray[0] = $FileIndex |
---|
1383 | Else |
---|
1384 | $DirectoryArray[0][0] = $DirectoryIndex |
---|
1385 | $FileArray[0][0] = $FileIndex |
---|
1386 | EndIf |
---|
1387 | |
---|
1388 | Switch $Return_Type |
---|
1389 | Case 0 |
---|
1390 | If $ArrayCount = 1 Then |
---|
1391 | ReDim $DirectoryArray[$DirectoryArray[0] + $FileArray[0] + 1] |
---|
1392 | For $i = 1 To $FileIndex |
---|
1393 | $DirectoryArray[$DirectoryArray[0] + $i] = $FileArray[$i] |
---|
1394 | Next |
---|
1395 | $DirectoryArray[0] += $FileArray[0] |
---|
1396 | Else |
---|
1397 | ReDim $DirectoryArray[$DirectoryArray[0][0] + $FileArray[0][0] + 1][$ArrayCount] |
---|
1398 | For $i = 1 To $FileIndex |
---|
1399 | For $j = 0 To $ArrayCount - 1 |
---|
1400 | $DirectoryArray[$DirectoryArray[0][0] + $i][$j] = $FileArray[$i][$j] |
---|
1401 | Next |
---|
1402 | Next |
---|
1403 | $DirectoryArray[0][0] += $FileArray[0][0] |
---|
1404 | EndIf |
---|
1405 | Return $DirectoryArray |
---|
1406 | Case 1 |
---|
1407 | If $ArrayCount = 1 Then |
---|
1408 | ReDim $DirectoryArray[$DirectoryIndex + 1] |
---|
1409 | Else |
---|
1410 | ReDim $DirectoryArray[$DirectoryIndex + 1][$ArrayCount] |
---|
1411 | EndIf |
---|
1412 | Return $DirectoryArray |
---|
1413 | Case 2 |
---|
1414 | If $ArrayCount = 1 Then |
---|
1415 | ReDim $FileArray[$FileIndex + 1] |
---|
1416 | Else |
---|
1417 | ReDim $FileArray[$FileIndex + 1][$ArrayCount] |
---|
1418 | EndIf |
---|
1419 | Return $FileArray |
---|
1420 | EndSwitch |
---|
1421 | EndFunc ;==>__FTP_ListToArray |
---|
1422 | |
---|
1423 | ; #INTERNAL_USE_ONLY# =========================================================================================================== |
---|
1424 | ; Name...........: __FTP_Init |
---|
1425 | ; Description ...: DllOpen wininet.dll |
---|
1426 | ; Syntax.........: __FTP_Init() |
---|
1427 | ; Parameters ....: |
---|
1428 | ; Return values .: |
---|
1429 | ; Author ........: |
---|
1430 | ; Modified.......: |
---|
1431 | ; Remarks .......: |
---|
1432 | ; Related .......: |
---|
1433 | ; Link ..........: |
---|
1434 | ; Example .......: |
---|
1435 | ; =============================================================================================================================== |
---|
1436 | Func __FTP_Init() |
---|
1437 | $__ghWinInet_FTP = DllOpen('wininet.dll') |
---|
1438 | EndFunc ;==>__FTP_Init |
---|