Jump to content



Photo

FTP.au3


  • Please log in to reply
12 replies to this topic

#1 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,513 posts

Posted 01 May 2009 - 02:20 PM

Here is my version of FTP library.

Used ideas from: Prog@ndy, Wouter van Kesteren, Beast, and Bill Mezian.

AutoIt         
#Region Header #cs     Title:          FTP UDF Library for AutoIt3     Filename:       FTP.au3     Description:    Allows you to work with FTP servers     Author:         Yashied     Version:        1.0     Requirements:   AutoIt v3.3 +, Developed/Tested on WindowsXP Pro Service Pack 2     Uses:           WinAPI.au3     Notes:          Used ideas from: Prog@ndy, Wouter van Kesteren, Beast, and Bill Mezian                     Original FTP_Ex.au3 library can be found at the following link                     <a href='http://www.autoit.de/index.php?page=Thread&postID=48393' class='bbc_url' title='External link' rel='nofollow external'>http://www.autoit.de/index.php?page=Thread&postID=48393</a>     Available functions:     _FTP_Startup     _FTP_Shutdown     _FTP_Open     _FTP_Close     _FTP_Connect     _FTP_Disconnect     _FTP_GetCurrentDir     _FTP_SetCurrentDir     _FTP_CreateDir     _FTP_DeleteDir     _FTP_OpenFile     _FTP_CloseFile     _FTP_DeleteFile     _FTP_RenameFile     _FTP_FileFindFirst     _FTP_FileFindNext     _FTP_FileFindClose     _FTP_ReadFile     _FTP_WriteFile     _FTP_GetFileSize     _FTP_GetFile     _FTP_PutFile     Additional features:     _FileSizeLoHi     _InternetGetOption     _InternetGetOptionW     _InternetSetOption     _InternetSetOptionW     _IsInternet     Example1:         #Include <FTP.au3>         const $Host = 'ftp.mozilla.org'         const $Login = ''         const $Password = ''         local $hFtp, $hSession, $hFile, $tBuffer, $nSize, $nBytes         _FTP_Startup()         $hFtp = _FTP_Open('MyFtp')         $hSession = _FTP_Connect($hFtp, $Host, $Login, $Password)         $hFile = _FTP_OpenFile($hSession, 'README')         $nSize = _FTP_GetFileSize($hFile)         $tBuffer = DllStructCreate('byte[' & $nSize & ']')         _FTP_ReadFile($hFile, $tBuffer, $nSize)         _FTP_CloseFile($hFile)         $hFile = _WinAPI_CreateFile('README', 1)         _WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), $nSize, $nBytes)         _WinAPI_CloseHandle($hFile)         _FTP_Disconnect($hSession)         _FTP_Close($hFtp)         _FTP_Shutdown()     Example2:         #Include <FTP.au3>         const $Host = 'ftp.mozilla.org'         const $Login = ''         const $Password = ''         local $hFtp, $hSession, $hFind, $tFind         _FTP_Startup()         $hFtp = _FTP_Open('MyFtp')         $hSession = _FTP_Connect($hFtp, $Host, $Login, $Password)         $tFind = DllStructCreate($tagWIN32_FIND_DATA)         $hFind = _FTP_FileFindFirst($hSession, '', $tFind)         while not @error             ConsoleWrite(DllStructGetData($tFind, 'FileName') & @CR)             _FTP_FileFindNext($hFind, $tFind)         wend         _FTP_FileFindClose($hFind)                 _FTP_Disconnect($hSession)         _FTP_Close($hFtp)         _FTP_Shutdown() #ce #Include-once #Include <WinAPI.au3> #EndRegion Header #Region Global Variables and Constants ; Internet Flags. ; INTERNET_FLAG_ASYNC ; Makes only asynchronous requests on handles descended from the handle returned from this function. ; Only the _FTP_Open() function uses this flag. ; INTERNET_FLAG_EXISTING_CONNECT ; Attempts to use an existing InternetConnect object if one exists with the same attributes required to make the request. ; This is useful only with FTP operations, since FTP is the only protocol that typically performs multiple operations ; during the same session. WinINet caches a single connection handle for each HINTERNET handle generated by _FTP_Open(). ; Only the _FTP_Connect() function use this flag. ; INTERNET_FLAG_FROM_CACHE ; Does not make network requests. All entities are returned from the cache. If the requested item is not in the cache, ; a suitable error, such as ERROR_FILE_NOT_FOUND, is returned. ; Only the _FTP_Open() function uses this flag. ; INTERNET_FLAG_HYPERLINK ; Forces a reload if there is no Expires time and no LastModified time returned from the server when determining ; whether to reload the item from the network. ; This flag can be used by _FTP_FileFindFirst(), _FTP_GetFile(), _FTP_OpenFile(), and _FTP_PutFile(). ; INTERNET_FLAG_MUST_CACHE_REQUEST ; Identical to the preferred value, INTERNET_FLAG_NEED_FILE. Causes a temporary file to be created if the file cannot be cached. ; This flag can be used by _FTP_FileFindFirst(), _FTP_GetFile(), _FTP_OpenFile(), and _FTP_PutFile(). ; INTERNET_FLAG_NEED_FILE ; Causes a temporary file to be created if the file cannot be cached. ; This flag can be used by _FTP_FileFindFirst(), _FTP_GetFile(), _FTP_OpenFile(), and _FTP_PutFile(). ; INTERNET_FLAG_OFFLINE ; Identical to INTERNET_FLAG_FROM_CACHE. Does not make network requests. All entities are returned from the cache. ; If the requested item is not in the cache, a suitable error, such as ERROR_FILE_NOT_FOUND, is returned. ; Only the _FTP_Open() function uses this flag. ; INTERNET_FLAG_PASSIVE ; Uses passive FTP semantics. ; Only the _FTP_Connect() function uses this flag. ; INTERNET_FLAG_RELOAD ; Forces a download of the requested file, object, or directory listing from the origin server, not from the cache. ; This flag can be used by _FTP_FileFindFirst(), _FTP_GetFile(), _FTP_OpenFile(), and _FTP_PutFile(). ; INTERNET_FLAG_RESYNCHRONIZE ; Reloads all FTP resources if the resource has been modified since the last time it was downloaded. ; This flag can be used by _FTP_FileFindFirst(), _FTP_GetFile(), _FTP_OpenFile(), and _FTP_PutFile(). ; INTERNET_FLAG_TRANSFER_ASCII ; Transfers file as ASCII. ; This flag can be used by _FTP_OpenFile(), _FTP_GetFile(), and _FTP_PutFile(). ; INTERNET_FLAG_TRANSFER_BINARY ; Transfers file as binary. ; This flag can be used by _FTP_OpenFile(), _FTP_GetFile(), and _FTP_PutFile(). global const $INTERNET_FLAG_ASYNC = 0x10000000 global const $INTERNET_FLAG_EXISTING_CONNECT = 0x20000000 global const $INTERNET_FLAG_FROM_CACHE = 0x01000000 global const $INTERNET_FLAG_HYPERLINK = 0x00000400 global const $INTERNET_FLAG_MUST_CACHE_REQUEST = 0x00000010 global const $INTERNET_FLAG_NEED_FILE = 0x00000010 global const $INTERNET_FLAG_OFFLINE = 0x01000000 global const $INTERNET_FLAG_PASSIVE = 0x08000000 global const $INTERNET_FLAG_RELOAD = 0x80000000 global const $INTERNET_FLAG_RESYNCHRONIZE = 0x00000800 global const $INTERNET_FLAG_TRANSFER_ASCII = 0x00000001 global const $INTERNET_FLAG_TRANSFER_BINARY = 0x00000002 ; Option Flags. ; This flags can be used by _InternetGetOption() and _InternetSetOption(). ; INTERNET_OPTION_CONNECT_TIMEOUT ; Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to use for Internet connection requests. ; Setting this option to infinite (0xFFFFFFFF) will disable this timer. ; If a connection request takes longer than this time-out value, the request is canceled. When attempting to connect to multiple IP addresses ; for a single host (a multihome host), the timeout limit is cumulative for all of the IP addresses. This option can be used on any HINTERNET handle, ; including a NULL handle. ; INTERNET_OPTION_CONNECT_RETRIES ; Sets or retrieves an unsigned long integer value that contains the number of times WinINet attempts to resolve and connect to a host. ; It only attempts once per IP address. For example, if you attempt to connect to a multihome host that has ten IP addresses and ; INTERNET_OPTION_CONNECT_RETRIES is set to seven, WinINet only attempts to resolve and connect to the first seven IP addresses. ; Conversely, given the same set of ten IP addresses, if INTERNET_OPTION_CONNECT_RETRIES is set to 20, WinINet attempts each of the ten only once. ; If a host has only one IP address and the first connection attempt fails, there are no further attempts. If a connection attempt still ; fails after the specified number of attempts, the request is canceled. The default value for INTERNET_OPTION_CONNECT_RETRIES is five attempts. ; This option can be used on any HINTERNET handle, including a NULL handle. ; INTERNET_OPTION_CONTROL_SEND_TIMEOUT ; Identical to INTERNET_OPTION_SEND_TIMEOUT. ; INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT ; Identical to INTERNET_OPTION_RECEIVE_TIMEOUT ; INTERNET_OPTION_SEND_TIMEOUT ; Sets or retrieves an unsigned long integer value, in milliseconds, that contains the time-out value to send a request. If the send takes ; longer than this time-out value, the send is canceled. This option can be used on any HINTERNET handle, including a NULL handle. ; INTERNET_OPTION_RECEIVE_TIMEOUT ; Sets or retrieves an unsigned long integer value that contains the time-out value, in milliseconds, to receive a response to a request. ; If the response takes longer than this time-out value, the request is canceled. This option can be used on any HINTERNET handle, ; including a NULL handle. ; INTERNET_OPTION_READ_BUFFER_SIZE ; Sets or retrieves an unsigned long integer value that contains the size of the read buffer. This option can be used on HINTERNET handles ; returned by _FTP_Open(), _FTP_FileFindFirst(), and _FTP_Connect(). ; INTERNET_OPTION_WRITE_BUFFER_SIZE ; Sets or retrieves an unsigned long integer value that contains the size, in bytes, of the write buffer. This option can be ; used on HINTERNET handles returned by _FTP_Open() and _FTP_Connect() ; INTERNET_OPTION_USERNAME ; Sets or retrieves a string that contains the user name associated with a handle returned by _FTP_Connect(). ; INTERNET_OPTION_PASSWORD ; Sets or retrieves a string value that contains the password associated with a handle returned by _FTP_Connect(). ; INTERNET_OPTION_PROXY ; Sets or retrieves an INTERNET_PROXY_INFO structure that contains the proxy data for an existing _FTP_Open() handle when the HINTERNET handle is not NULL. ; If the HINTERNET handle is NULL, the function sets or queries the global proxy data. This option can be used on the handle returned by _FTP_Open(). ; INTERNET_OPTION_USER_AGENT ; Sets or retrieves the user agent string on handles supplied by _FTP_Open() function. ; INTERNET_OPTION_CONTEXT_VALUE ; Sets or retrieves a DWORD_PTR that contains the address of the context value associated with this HINTERNET handle. This option can be used ; on any HINTERNET handle. Previously, this set the context value to the address stored in the lpBuffer pointer. This has been corrected so that the ; value stored in the buffer is used and the INTERNET_OPTION_CONTEXT_VALUE flag is assigned a new value. The old value, 10, has been preserved so that ; applications written for the old behavior are still supported. global const $INTERNET_OPTION_CONNECT_TIMEOUT = 2 global const $INTERNET_OPTION_CONNECT_RETRIES = 3 global const $INTERNET_OPTION_CONTROL_SEND_TIMEOUT = 5 global const $INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT = 6 global const $INTERNET_OPTION_SEND_TIMEOUT = 5 global const $INTERNET_OPTION_RECEIVE_TIMEOUT = 6 global const $INTERNET_OPTION_READ_BUFFER_SIZE = 12 global const $INTERNET_OPTION_WRITE_BUFFER_SIZE = 13 global const $INTERNET_OPTION_USERNAME = 28 global const $INTERNET_OPTION_PASSWORD = 29 global const $INTERNET_OPTION_PROXY = 38 global const $INTERNET_OPTION_USER_AGENT = 41 global const $INTERNET_OPTION_CONTEXT_VALUE = 45 ; File Attributes. ; FILE_ATTRIBUTE_ARCHIVE ; The file should be archived. Applications use this attribute to mark files for backup or removal. ; FILE_ATTRIBUTE_ENCRYPTED ; The file or directory is encrypted. For a file, this means that all data in the file is encrypted. For a directory, this means that encryption is the ; default for newly created files and subdirectories. For more information, see File Encryption. This flag has no effect if FILE_ATTRIBUTE_SYSTEM ; is also specified. ; FILE_ATTRIBUTE_HIDDEN ; The file is hidden. Do not include it in an ordinary directory listing. ; FILE_ATTRIBUTE_NORMAL ; The file does not have other attributes set. This attribute is valid only if used alone. ; FILE_ATTRIBUTE_OFFLINE ; The data of a file is not immediately available. This attribute indicates that file data is physically moved to offline storage. This attribute ; is used by Remote Storage, the hierarchical storage management software. Applications should not arbitrarily change this attribute. ; FILE_ATTRIBUTE_READONLY ; The file is read only. Applications can read the file, but cannot write to or delete it. ; FILE_ATTRIBUTE_SYSTEM ; The file is part of or used exclusively by an operating system. ; FILE_ATTRIBUTE_TEMPORARY ; The file is being used for temporary storage. global const $FILE_ATTRIBUTE_ARCHIVE = 0x0020 global const $FILE_ATTRIBUTE_ENCRYPTED = 0x4000 global const $FILE_ATTRIBUTE_HIDDEN = 0x0002 global const $FILE_ATTRIBUTE_NORMAL = 0x0080 global const $FILE_ATTRIBUTE_OFFLINE = 0x1000 global const $FILE_ATTRIBUTE_READONLY = 0x0001 global const $FILE_ATTRIBUTE_SYSTEM = 0x0004 global const $FILE_ATTRIBUTE_TEMPORARY = 0x0100 ; Error Messages. ; If necessary, you can use WinINetErrorMessages.au3 containing error constants are specific to the WinINet functions. ; INTERNET_PROXY_INFO Structure. ; Contains information that is supplied with the INTERNET_OPTION_PROXY value to get or set proxy information on a handle ; obtained from a call to the _FTP_Open() function. ; AccessType            - Access type. ; Proxy                 - Pointer to a string that contains the proxy server list. ; ProxyBypass           - Pointer to a string that contains the proxy bypass list. global const $tagINTERNET_PROXY_INFO = 'dword AccessType;ptr Proxy;ptr ProxyBypass;' ; WIN32_FIND_DATA Structure. ; Contains information about the file that is found by the _FTP_FileFindFirst() and _FTP_FileFindNext() function. ; FileAttributes        - The file attributes of a file. This parameter can be a combination of the following values. ; CreationTime          - A FILETIME structure that specifies when a file or directory was created. If the underlying ;                         file system does not support creation time, this member is zero (0). ; LastAccessTime        - A FILETIME structure. ; LastWriteTime         - A FILETIME structure. ; FileSizeHigh          - The high-order DWORD value of the file size, in bytes. This value is zero (0) ;                         unless the file size is greater than MAXDWORD. ; FileSizeLow           - The low-order DWORD value of the file size, in bytes. ; Reserved0             - If the FileAttributes member includes the FILE_ATTRIBUTE_REPARSE_POINT attribute, this member specifies ;                         the reparse point tag. Otherwise, this value is undefined and should not be used. ; Reserved1             - Reserved for future use. ; FileName[MAX_PATH]    - The name of the file. ; AlternateFileName[14] - An alternative name for the file. This name is in the classic 8.3 (filename.ext) file name format. global const $tagWIN32_FIND_DATA = 'dword FileAttributes;dword CreationTime[2];dword LastAccessTime[2];dword LastWriteTime[2];dword FileSizeHigh;dword FileSizeLow;dword Reserved0;dword Reserved1;char FileName[1024];char AlternateFileName[14]' ; Description for the following constants, see _FTP_Open() and _FTP_OpenFile(). global const $INTERNET_OPEN_TYPE_DIRECT = 1 global const $INTERNET_OPEN_TYPE_PRECONFIG = 0 global const $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 global const $INTERNET_OPEN_TYPE_PROXY = 3 global const $GENERIC_READ = 0x80000000 global const $GENERIC_WRITE = 0x40000000 #EndRegion Global Variables and Constants #Region Local Variables and Constants global $WININET_DLL = -1 global $FtpRef = 0 #EndRegion Local Variables and Constants #Region Public Functions ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_Startup ; Description:      Initialize WinINet. ; Syntax:           _FTP_Startup (  ) ; Parameter(s):     None. ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. ; Author(s):        Yashied ; Note(s):          Call _FTP_Startup() before using any functions from this library. ;==================================================================================================================================== func _FTP_Startup()         if $FtpRef = 0 then         $WININET_DLL = DllOpen('wininet.dll')         if $WININET_DLL = -1 then             return SetError(1, 0, 0)         endif     endif         $FtpRef += 1         return SetError(0, 0, 1) endfunc; _FTP_Startup ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_Shutdown ; Description:      Clean up resources used by WinINet. ; Syntax:           _FTP_Shutdown (  ) ; Parameter(s):     None. ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. ; Author(s):        Yashied ; Note(s):          You must close all handles before you call _FTP_Shutdown() ;==================================================================================================================================== func _FTP_Shutdown()         if $FtpRef = 0 then         return SetError(1, 0, 0)     endif         $FtpRef -= 1         if $FtpRef = 0 then         DllClose($WININET_DLL)         $WININET_DLL = -1     endif         return SetError(0, 0, 1) endfunc; _FTP_Shutdown ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_Open ; Description:      Opens an FTP. ; Syntax:           _FTP_Open ( $sAgent [, $lAccessType [, $sProxyName [, $sProxyBypass [, $lFlags]]]] ) ; Parameter(s):     $sAgent        - Any name (usually the name of the application). ;                   $lAccessType   - [optional] Type of access required. This parameter can be one of the following values. Default is INTERNET_OPEN_TYPE_DIRECT. ; ;                                    INTERNET_OPEN_TYPE_DIRECT ;                                    Resolves all host names locally. ; ;                                    INTERNET_OPEN_TYPE_PRECONFIG ;                                    Retrieves the proxy or direct configuration from the registry. ; ;                                    INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY ;                                    Retrieves the proxy or direct configuration from the registry and prevents the use of a startup ;                                    Microsoft JScript or Internet Setup (INS) file. ; ;                                    INTERNET_OPEN_TYPE_PROXY ;                                    Passes requests to the proxy unless a proxy bypass list is supplied and the name to be resolved bypasses the proxy. ;                                    In this case, the function uses INTERNET_OPEN_TYPE_DIRECT. ; ;                   $lFlags        - [optional] Special flag(s). This parameter can be a combination of the following values. ; ;                                    INTERNET_FLAG_ASYNC ;                                    INTERNET_FLAG_FROM_CACHE ;                                    INTERNET_FLAG_OFFLINE ; ;                                    (See constants section in this library) ; ;                   $sProxyName    - [optional] The name of the proxy server(s) to use when proxy access is specified by setting $lAccessType to INTERNET_OPEN_TYPE_PROXY. ;                                    Do not use an empty string, because _FTP_Open() will use it as the proxy name. If $lAccessType is not set to INTERNET_OPEN_TYPE_PROXY, ;                                    this parameter is ignored and should be NULL. ; ;                   $sProxyBypass  - [optional] The list of host names or IP addresses, or both, that should not be routed through the proxy when $lAccessType ;                                    is set to INTERNET_OPEN_TYPE_PROXY. Do not use an empty string, because _FTP_Open() will use it as the proxy bypass list. ;                                    If this parameter specifies the "<local>" macro as the only entry, the function bypasses any host name that does not contain a period. ;                                    If $lAccessType is not set to INTERNET_OPEN_TYPE_PROXY, this parameter is ignored and should be NULL. ; ; Return Value(s):  Success: Returns a valid handle ($hFtp) that the application passes to subsequent functions. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; ; Note(s):          The application can make any number of calls to _FTP_Open(), though a single call is normally sufficient. The application might need to define ;                   separate behaviors for each _FTP_Open() instance, such as different proxy servers configured for each. ;==================================================================================================================================== func _FTP_Open($sAgent, $lAccessType = 1, $lFlags = 0, $sProxyName = '', $sProxyBypass = '')         local $Ret = DllCall($WININET_DLL, 'hwnd', 'InternetOpen', 'str', $sAgent, 'dword', $lAccessType, 'str', $sProxyName, 'str', $sProxyBypass, 'dword', $lFlags)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Ret[0]) endfunc; _FTP_Open ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_Close ; Description:      Closes an FTP. ; Syntax:           _FTP_Close ( $hFtp ) ; Parameter(s):     $hFtp  - Handle of FTP to close. ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_Close($hFtp)         local $Ret = DllCall($WININET_DLL, 'int', 'InternetCloseHandle', 'hwnd', $hFtp)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_Close ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_Connect ; Description:      Connects to an FTP server. ; Syntax:           _FTP_Connect ( $hFtp, $sServerName,  $sUsername, $sPassword [, $lServerPort [, $lFlags [, $lContext]]] ) ; Parameter(s):     $hFtp          - Handle returned by a previous call to _FTP_Open(). ;                   $sServerName   - The host name of an Internet server. ;                   $sUsername     - The name of the user to log on. If this parameter is NULL, the function uses an appropriate default is "anonymous". ; ;                   $sPassword     - The password to use to log on. If both $sServerName and $sUsername are NULL, the function uses the default "anonymous" password. ;                                    If $sPassword is NULL, but $sUsername is not NULL, the function uses a blank password. ; ;                   $lServerPort   - [optional] Server port. Default is 0 (21). ;                   $lFlags        - [optional] Special flag(s). This parameter can be a combination of the following values. ; ;                                    INTERNET_FLAG_EXISTING_CONNECT ;                                    INTERNET_FLAG_PASSIVE ;                                   ;                                    (See constants section in this library) ; ;                   $lContext      - [optional] Pointer to a variable that contains an application-defined value that is used to identify the ;                                    application context for the returned handle in callbacks. ; ; Return Value(s):  Success: Returns a valid handle ($hSession) to the session. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_Connect($hFtp, $sServerName, $sUsername, $sPassword, $lServerPort = 0, $lFlags = 0x08000000, $lContext = 0)         local $Ret = DllCall($WININET_DLL, 'hwnd', 'InternetConnect', 'hwnd', $hFtp, 'str', $sServerName, 'int', $lServerPort, 'str', $sUsername, 'str', $sPassword, 'dword', 1, 'dword', $lFlags, 'dword', $lContext)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Ret[0]) endfunc; _FTP_Connect ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_Disconnect ; Description:      Disconnects from an FTP server. ; Syntax:           _FTP_Disconnect ( $hSession ) ; Parameter(s):     $hSession - Handle to an FTP session. ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_Disconnect($hSession)         local $Ret = DllCall($WININET_DLL, 'int', 'InternetCloseHandle', 'hwnd', $hSession)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_Disconnect ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_GetCurrentDir ; Description:      Retrieves the current directory for the specified FTP session. ; Syntax:           _FTP_GetCurrentDir ( $hSession ) ; Parameter(s):     $hSession - Handle to an FTP session. ; Return Value(s):  Success: Returns the absolute path of the current directory. ;                   Failure: Returns empty string and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_GetCurrentDir($hSession)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpGetCurrentDirectory', 'hwnd', $hSession, 'str', '', 'dword*', 1024)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Ret[2]) endfunc; _FTP_GetCurrentDir ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_SetCurrentDir ; Description:      Changes directory on the FTP server. ; Syntax:           _FTP_SetCurrentDir ( $hSession, $sDir ) ; Parameter(s):     $hSession - Handle to an FTP session. ;                   $sDir     - The name of the directory to become the current working directory. This can be either a fully ;                               qualified path or a name relative to the current directory. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_SetCurrentDir($hSession, $sDir)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpSetCurrentDirectory', 'hwnd', $hSession, 'str', $sDir)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_SetCurrentDir ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_CreateDir ; Description:      Creates a new directory on the FTP server. ; Syntax:           _FTP_CreateDir ( $hSession, $sDir ) ; Parameter(s):     $hSession - Handle to an FTP session. ;                   $sDir     - The name of the directory to be created. This can be either a fully qualified path or a name relative ;                               to the current directory. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_CreateDir($hSession, $sDir)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpCreateDirectory', 'hwnd', $hSession, 'str', $sDir)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endIf         return SetError(0, 0, 1) endfunc; _FTP_CreateDir ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_DeleteDir ; Description:      Removes the specified directory on the FTP server. ; Syntax:           _FTP_DeleteDir ( $hSession, $sDir ) ; Parameter(s):     $hSession - Handle to an FTP session. ;                   $sDir     - The name of the directory to be removed. This can be either a fully qualified path or a name relative ;                               to the current directory. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_DeleteDir($hSession, $sDir)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpRemoveDirectory', 'hwnd', $hSession, 'str', $sDir)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_DeleteDir ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_OpenFile ; Description:      Initiates access to a remote file on an FTP server for reading or writing. ; Syntax:           _FTP_OpenFile ( $hSession, $sFileName,  [, $lAccess [, $lFlags [, $lContext]]] ) ; Parameter(s):     $hSession      - Handle to an FTP session. ;                   $sFileName     - The name of the file to be accessed. This parameter can be either a partially or fully qualified file name relative ;                                    to the current directory. ; ;                   $lAccess       - [optional] File access. This parameter can be GENERIC_READ or GENERIC_WRITE, but not both. Default is GENERIC_READ. ;                   $lFlags        - [optional] Special flag(s). The application should select one transfer type and any of the ;                                    flags that indicate how the caching of the file will be controlled. ; ;                                    The transfer type can be one of the following values. ; ;                                    INTERNET_FLAG_TRANSFER_ASCII ;                                    INTERNET_FLAG_TRANSFER_BINARY ; ;                                    The following values are used to control the caching of the file. The application can use ;                                    one or more of these values. ; ;                                    INTERNET_FLAG_HYPERLINK ;                                    INTERNET_FLAG_NEED_FILE ;                                    INTERNET_FLAG_RELOAD ;                                    INTERNET_FLAG_RESYNCHRONIZE ;                                   ;                                    (See constants section in this library) ; ;                   $lContext      - [optional] Pointer to a variable that contains an application-defined value that is used to identify the ;                                    application context for the returned handle in callbacks. ; ; Return Value(s):  Success: Returns a handle ($hFile) to a specified file. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; ; Note(s):          After calling _FTP_OpenFile() and until calling _FTP_CloseFile(), all other calls to FTP functions on the same FTP session handle ;                   will fail and set the error message to ERROR_FTP_TRANSFER_IN_PROGRESS. After the calling application has finished using the HINTERNET ;                   handle returned by _FTP_OpenFile(), it must be closed using the _FTP_OpenFile() function. ; ;                   Only one file can be open in a single FTP session. Therefore, no file handle is returned and the application simply uses the FTP ;                   session handle when necessary. ;==================================================================================================================================== func _FTP_OpenFile($hSession, $sFileName, $lAccess = 0x80000000, $lFlags = 2, $lContext = 0)     local $Ret = DllCall($WININET_DLL, 'hwnd', 'FtpOpenFile', 'hwnd', $hSession, 'str', $sFileName, 'dword', $lAccess , 'dword', $lFlags, 'dword', $lContext)                             if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Ret[0]) endfunc; _FTP_OpenFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_CloseFile ; Description:      Closes an open remote file. ; Syntax:           _FTP_CloseFile ( $hFile ) ; Parameter(s):     $hFile - Handle returned by a previous call to _FTP_OpenFile(). ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_CloseFile($hFile)         local $Ret = DllCall($WININET_DLL, 'int', 'InternetCloseHandle', 'hwnd', $hFile)     if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_CloseFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_DeleteFile ; Description:      Deletes a file stored on the FTP server. ; Syntax:           _FTP_DeleteFile ( $hSession, $sFileName ) ; Parameter(s):     $hSession  - Handle to an FTP session. ;                   $sFileName - The name of the file to be deleted. This can be either partially or fully qualified file names relative ;                                to the current directory. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_DeleteFile($hSession, $sFileName)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpDeleteFile', 'hwnd', $hSession, 'str', $sFileName)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_DeleteFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_RenameFile ; Description:      Renames a file stored on the FTP server. ; Syntax:           _FTP_RenameFile ( $hSession, $sOldName, $sNewName ) ; Parameter(s):     $hSession - Handle to an FTP session. ;                   $sOldName - The name of the file to be renamed. ;                   $sNewName - The new name for the remote file. ; ;                   The $sOldName and $sNewName parameters can be either partially or fully qualified file names relative to the ;                   current directory. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_RenameFile($hSession, $sOldName, $sNewName)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpRenameFile', 'hwnd', $hSession, 'str', $sOldName, 'str', $sNewName)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_RenameFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_FileFindFirst ; Description:      Searches the specified directory of the given FTP session. ; Syntax:           _FTP_FileFindFirst ( $hSession, $sDir, ByRef $tFindFileData [, $lFlags [, $lContext]] ) ; Parameter(s):     $hSession      - Handle to an FTP session. ;                   $sDir          - String that specifies a valid directory path or file name for the FTP server's file system. ;                                    The string can contain wildcards, but no blank spaces are allowed. If the value of $sDir is NULL or if it ;                                    is an empty string, the function finds the first file in the current directory on the server. ; ;                   $tFindFileData - WIN32_FIND_DATA structure that receives information about the found file or directory. ;                   $lFlags        - [optional] Special flag(s). This parameter can be a combination of the following values. ; ;                                    INTERNET_FLAG_HYPERLINK ;                                    INTERNET_FLAG_NEED_FILE ;                                    INTERNET_FLAG_NO_CACHE_WRITE ;                                    INTERNET_FLAG_RELOAD ;                                    INTERNET_FLAG_RESYNCHRONIZE ; ;                                    (See constants section in this library) ; ;                   $lContext      - [optional] Pointer to a variable that contains an application-defined value that is used to identify the ;                                    application context for the returned handle in callbacks. ; ; Return Value(s):  Success: Returns a valid handle ($hFind) for the request and fills a WIN32_FIND_DATA structure. If the function finds ;                            no matching files is returned to 0. ; ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; ; Note(s):          After calling _FTP_FileFindFirst() and until calling _FTP_FileFindClose(), the application cannot call _FTP_FileFindFirst() ;                   again on the given FTP session handle. If a call is made to _FTP_FileFindFirst() on that handle, the function fails with ;                   ERROR_FTP_TRANSFER_IN_PROGRESS. After the calling application has finished using the HINTERNET handle returned by _FTP_FileFindFirst(), ;                   it must be closed using the _FTP_FileFindClose() function. ; ;                   After beginning a directory enumeration with _FTP_FileFindFirst(), the _FTP_FileFindNext() function can be used ;                   to continue the enumeration. ; ;                   The application cannot call _FTP_FileFindFirst() between calls to _FTP_OpenFile() and _FTP_CloseFile(). ;==================================================================================================================================== func _FTP_FileFindFirst($hSession, $sDir, ByRef $tFindFileData, $lFlags = 0, $lContext = 0)         local $Ret = DllCall($WININET_DLL, 'hwnd', 'FtpFindFirstFile', 'hwnd', $hSession, 'str', $sDir, 'ptr', DllStructGetPtr($tFindFileData), 'dword', $lFlags, 'dword', $lContext)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Ret[0]) endfunc; _FTP_FileFindFirst ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_FileFindNext ; Description:      ; Syntax:           _FTP_FileFindNext ( $hFind, ByRef $tFindFileData ) ; Parameter(s):     $hFind         - Handle returned from either _FTP_FileFindFirst(). ;                   $tFindFileData - WIN32_FIND_DATA structure that receives information about the found file or directory. ; ; Return Value(s):  Success: Returns 1 and fills a WIN32_FIND_DATA structure. If the function finds no matching files is returned to 0 ;                            and sets the @extended flag to ERROR_NO_MORE_FILES (18). ; ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_FileFindNext($hFind, ByRef $tFindFileData)         local $Ret = DllCall($WININET_DLL, 'int', 'InternetFindNextFile', 'hwnd', $hFind, 'ptr', DllStructGetPtr($tFindFileData))         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_FileFindNext ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_FileFindClose ; Description:      Closes an "FileFind" handle. ; Syntax:           _FTP_FileFindClose ( $hFind ) ; Parameter(s):     $hFind - Handle returned from either _FTP_FileFindFirst(). ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_FileFindClose($hFind)         local $Ret = DllCall($WININET_DLL, 'int', 'InternetCloseHandle', 'hwnd', $hFind)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_FileFindClose     ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_ReadFile ; Description:      Reads data from a handle opened by the _FTP_OpenFile() function. ; Syntax:           _FTP_ReadFile ( $hFile, ByRef $tBuffer, $lSize ) ; Parameter(s):     $hFile   - Handle returned from a previous call to _FTP_OpenFile(). ;                   $tBuffer - The structure ("byte[]" or "(w)char[]" - depending on the specified flag in _FTP_OpenFile() function call) ;                              containing the data to be written to the file. ;                   $lSize   - Number of bytes to be read. ; ; Return Value(s):  Success: Returns number of bytes read. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_ReadFile($hFile, ByRef $tBuffer, $lSize)         local $Ret, $sSize, $nSize = 0, $rError = 0     if (not IsDllStruct($tBuffer)) or (not IsNumber($lSize)) then         return SetError(1, 0, 0)     endif         $sSize = DllStructGetSize($tBuffer)     if $lSize > $sSize then         return SetError(1, 0, 0)     endif     $Ret = DllCall($WININET_DLL, 'int', 'InternetReadFile', 'hwnd', $hFile, 'ptr', DllStructGetPtr($tBuffer), 'dword', $lSize, 'dword*', 0)     if @error then         $rError = 1     else         $nSize = $Ret[4]         if $Ret[0] = 0 then             $rError = 1         endif     endif         return SetError($rError, _WinAPI_GetLastError(), $nSize) endfunc; _FTP_ReadFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_WriteFile ; Description:      Writes data to an open FTP file. ; Syntax:           _FTP_WriteFile ( $hFile, ByRef $tBuffer, $lSize ) ; Parameter(s):     $hFile   - Handle returned from a previous call to _FTP_OpenFile(). ;                   $tBuffer - The structure (byte[] or (w)char[] - depending on the specified flag in _FTP_OpenFile() function call) ;                              containing the data to be written to the file. ;                   $lSize   - Number of bytes to be written to the file. ; ; Return Value(s):  Success: Returns number of bytes written to the file ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_WriteFile($hFile, ByRef $tBuffer, $lSize)         local $Ret, $nSize = 0, $rError = 0         if (not IsDllStruct($tBuffer)) or (not IsNumber($lSize)) then         return SetError(1, 0, 0)     endif         $Ret = DllCall($WININET_DLL, 'int', 'InternetWriteFile', 'hwnd', $hFile, 'ptr', DllStructGetPtr($tBuffer), 'dword', $lSize, 'dword*', 0)     if @error then         $rError = 1     else         $nSize = $Ret[4]         if $Ret[0] = 0 then             $rError = 1         endif     endif         return SetError($rError, _WinAPI_GetLastError(), $nSize) endfunc; _FTP_WriteFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_GetFileSize ; Description:      Retrieves the file size of the requested FTP resource. ; Syntax:           _FTP_GetFileSize ( $hFile ) ; Parameter(s):     $hFile - Handle returned from a previous call to _FTP_OpenFile(). ; Return Value(s):  Success: Returns the file size in bytes. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _FTP_GetFileSize($hFile)         local $Ret = DllCall($WININET_DLL, 'dword', 'FtpGetFileSize', 'hwnd', $hFile, 'dword*', 0)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, _FileSizeLoHi($Ret[2], $Ret[0])) endfunc; _FTP_GetFileSize ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_GetFile ; Description:      Retrieves a file from the FTP server and stores it under the specified file name. ; Syntax:           _FTP_GetFile ( $hSession, $sRemoteFile, $sLocalFile [, $fFailIfExists [, $lAttributes [, $lFlags [, $lContext]]]] ) ; Parameter(s):     $hSession      - Handle to an FTP session. ;                   $sRemoteFile   - The name of the file to be retrieved. ;                   $sLocalFile    - The name of the file to be created on the local system. ;                   $fFailIfExists - [optional] Indicates whether the function should proceed if a local file of the specified name already exists. ;                                    If $fFailIfExists is TRUE and the local file exists, _FTP_GetFile() fails. Default is 0 - overwrite file. ; ;                   $lAttributes   - [optional] File attributes for the new file. This parameter can be a combination of the following values. ; ;                                    (See constants section in this library) ; ;                   $lFlags        - [optional] Special flag(s). The application should select one transfer type and any of the ;                                    flags that indicate how the caching of the file will be controlled. ; ;                                    The transfer type can be one of the following values. ; ;                                    INTERNET_FLAG_TRANSFER_ASCII ;                                    INTERNET_FLAG_TRANSFER_BINARY ; ;                                    The following values are used to control the caching of the file. The application can use ;                                    one or more of these values. ; ;                                    INTERNET_FLAG_HYPERLINK ;                                    INTERNET_FLAG_NEED_FILE ;                                    INTERNET_FLAG_RELOAD ;                                    INTERNET_FLAG_RESYNCHRONIZE ;                                   ;                                    (See constants section in this library) ; ;                   $lContext      - [optional] Pointer to a variable that contains an application-defined value that is used to identify the ;                                    application context for the returned handle in callbacks. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; ; Note(s):          _FTP_GetFile() is a high-level routine that handles all the bookkeeping and overhead associated with reading a file ;                   from an FTP server and storing it locally. An application that needs to retrieve file data only or that requires close control ;                   over the file transfer should use the _FTP_OpenFile() and _FTP_ReadFile() functions. ;==================================================================================================================================== func _FTP_GetFile($hSession, $sRemoteFile, $sLocalFile, $fFailIfExists = 0, $lAttributes = 0, $lFlags = 0, $lContext = 0)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpGetFile', 'hwnd', $hSession, 'str', $sRemoteFile, 'str', $sLocalFile, 'int', $fFailIfExists,  'dword', $lAttributes, 'dword', $lFlags, 'dword', $lContext)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_GetFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FTP_PutFile ; Description:      Stores a file on the FTP server. ; Syntax:           _FTP_PutFile ( $hSession, $sLocalFile, $sRemoteFile [, $lFlags [, $lContext]] ) ; Parameter(s):     $hSession      - Handle to an FTP session. ;                   $sLocalFile    - The name of the file to be sent from the local system. ;                   $sRemoteFile   - The name of the file to be created on the remote system. ;                   $lFlags        - [optional] Special flag(s). The application should select one transfer type and any of the ;                                    flags that indicate how the caching of the file will be controlled. ; ;                                    The transfer type can be one of the following values. ; ;                                    INTERNET_FLAG_TRANSFER_ASCII ;                                    INTERNET_FLAG_TRANSFER_BINARY ; ;                                    The following values are used to control the caching of the file. The application can use ;                                    one or more of these values. ; ;                                    INTERNET_FLAG_HYPERLINK ;                                    INTERNET_FLAG_NEED_FILE ;                                    INTERNET_FLAG_RELOAD ;                                    INTERNET_FLAG_RESYNCHRONIZE ;                                   ;                                    (See constants section in this library) ; ;                   $lContext      - [optional] Pointer to a variable that contains an application-defined value that is used to identify the ;                                    application context for the returned handle in callbacks. ; ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; ; Note(s):          _FTP_PutFile() is a high-level routine that handles all the bookkeeping and overhead associated with reading a file ;                   locally and storing it on an FTP server. An application that needs to send file data only, or that requires close control ;                   over the file transfer, should use the _FTP_OpenFile() and _FTP_WriteFile() functions. ;==================================================================================================================================== func _FTP_PutFile($hSession, $sLocalFile, $sRemoteFile, $lFlags = 0, $lContext = 0)         local $Ret = DllCall($WININET_DLL, 'int', 'FtpPutFile', 'hwnd', $hSession, 'str', $sLocalFile, 'str', $sRemoteFile, 'dword', $lFlags, 'dword', $lContext)         if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, 1) endfunc; _FTP_PutFile ; #FUNCTION# ======================================================================================================================== ; Function Name:    _FileSizeLoHi ; Description:      Returns the file size by using the high-order and low-order DWORD values. ; Syntax:           _FileSizeLoHi ( $LoDWORD, $HiDWORD ) ; Parameter(s):     $LoDWORD - The low-order DWORD value of the file size, in bytes. ;                   $HiDWORD - The high-order DWORD value of the file size, in bytes. ; ; Return Value(s):  Returns the file size in bytes. ; Author(s):        Yashied ; Note(s):          Used to get file size from the WIN32_FIND_DATA structure. ;==================================================================================================================================== func _FileSizeLoHi($LoDWORD, $HiDWORD)     return BitOR(BitShift($LoDWORD, -32), BitAND($HiDWORD, 0xFFFFFFFF)) endfunc; _FileSizeLoHi ; #FUNCTION# ======================================================================================================================== ; Function Name:    _InternetGetOption, _InternetGetOptionW ; Description:      Queries an Internet option on the specified handle. ; Syntax:           _InternetGetOption ( $hInternet, $lOption ) ; Parameter(s):     $hInternet - Handle on which to query information. ;                   $lOption   - Internet option to be queried. This can be one of the Option Flags values. ; ;                                (See constants section in this library) ; ; Return Value(s):  Success: Returns the current value of the option. Type of return variable depends on the specified option. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          _InternetGetOptionW designed to UNICODE wide character string. ;==================================================================================================================================== func _InternetGetOption($hInternet, $lOption)         local $Ret, $tBuffer         switch $lOption         case 2, 3, 5, 6, 12, 13             $tBuffer = DllStructCreate('int')         case 28, 29, 41             $tBuffer = DllStructCreate('char[1024]')         case 38             $tBuffer = DllStructCreate($tagINTERNET_PROXY_INFO)         case 45             $tBuffer = DllStructCreate('ptr')         case else             return SetError(1, 0, 0)     endswitch         $Ret = DllCall($WININET_DLL, 'int', 'InternetQueryOption', 'hwnd', $hInternet, 'dword', $lOption, 'ptr', DllStructGetPtr($tBuffer), 'dword*', DllStructGetSize($tBuffer))     if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         switch $lOption         case 38             return SetError(0, 0, $tBuffer)         case else             return SetError(0, 0, DllStructGetData($tBuffer, 1))     endswitch endfunc; _InternetGetOption func _InternetGetOptionW($hInternet, $lOption)         local $Ret, $tBuffer         switch $lOption         case 2, 3, 5, 6, 12, 13             $tBuffer = DllStructCreate('int')         case 28, 29, 41             $tBuffer = DllStructCreate('wchar[1024]')         case 38             $tBuffer = DllStructCreate($tagINTERNET_PROXY_INFO)         case 45             $tBuffer = DllStructCreate('ptr')         case else             return SetError(1, 0, 0)     endswitch         $Ret = DllCall($WININET_DLL, 'int', 'InternetQueryOption', 'hwnd', $hInternet, 'dword', $lOption, 'ptr', DllStructGetPtr($tBuffer), 'dword*', DllStructGetSize($tBuffer))     if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         switch $lOption         case 38             return SetError(0, 0, $tBuffer)         case else             return SetError(0, 0, DllStructGetData($tBuffer, 1))     endswitch endfunc; _InternetGetOptionW ; #FUNCTION# ======================================================================================================================== ; Function Name:    _InternetSetOption, _InternetSetOptionW ; Description:      Sets an Internet option. ; Syntax:           _InternetGetOption ( $hInternet, $lOption, $lValue ) ; Parameter(s):     $hInternet - Handle on which to set information. ;                   $lOption   - Internet option to be set. This can be one of the Option Flags values. ; ;                                (See constants section in this library) ; ;                   $lValue    - The value that must be set. Type of variable depends on the specified options. ; ; Return Value(s):  Success: Returns the previous value of the option. Type of return variable depends on the specified options. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          _InternetSetOptionW designed to UNICODE wide character string. ;==================================================================================================================================== func _InternetSetOption($hInternet, $lOption, $lValue)         local $Ret, $Back, $tBuffer         switch $lOption         case 2, 3, 5, 6, 12, 13             if IsInt($lValue) then                 $tBuffer = DllStructCreate('int')             endif         case 28, 29, 41             if IsString($lValue) then                 $tBuffer = DllStructCreate('char[' & StringLen($lValue) + 1 & ']')             endif         case 38             if IsDllStruct($lValue) then                 $tBuffer = DllStructCreate($tagINTERNET_PROXY_INFO, DllStructGetPtr($lValue))             endif         case 45             if IsPtr($lValue) then                 $tBuffer = DllStructCreate('ptr')             endif         case else             return SetError(1, 0, 0)     endswitch     if not ($lOption = 38) then         DllStructSetData($tBuffer, 1, $lValue)     endif     $Back = _InternetGetOption($hInternet, $lOption)     if (@error) then         return SetError(1, @extended, 0)     endif     $Ret = DllCall($WININET_DLL, 'int', 'InternetSetOption', 'hwnd', $hInternet, 'dword', $lOption, 'ptr', DllStructGetPtr($tBuffer), 'dword', DllStructGetSize($tBuffer))     if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Back) endfunc; _InternetSetOption func _InternetSetOptionW($hInternet, $lOption, $lValue)         local $Ret, $Back, $tBuffer         switch $lOption         case 2, 3, 5, 6, 12, 13             if IsInt($lValue) then                 $tBuffer = DllStructCreate('int')             endif         case 28, 29, 41             if IsString($lValue) then                 $tBuffer = DllStructCreate('wchar[' & StringLen($lValue) + 1 & ']')             endif         case 38             if IsDllStruct($lValue) then                 $tBuffer = DllStructCreate($tagINTERNET_PROXY_INFO, DllStructGetPtr($lValue))             endif         case 45             if IsPtr($lValue) then                 $tBuffer = DllStructCreate('ptr')             endif         case else             return SetError(1, 0, 0)     endswitch     if not ($lOption = 38) then         DllStructSetData($tBuffer, 1, $lValue)     endif     $Back = _InternetGetOptionW($hInternet, $lOption)     if (@error) then         return SetError(1, @extended, 0)     endif     $Ret = DllCall($WININET_DLL, 'int', 'InternetSetOption', 'hwnd', $hInternet, 'dword', $lOption, 'ptr', DllStructGetPtr($tBuffer), 'dword', DllStructGetSize($tBuffer))     if (@error) or ($Ret[0] = 0) then         return SetError(1, _WinAPI_GetLastError(), 0)     endif         return SetError(0, 0, $Back) endfunc; _InternetSetOptionW ; #FUNCTION# ======================================================================================================================== ; Function Name:    _IsInternet ; Description:      Check for Internet connection. ; Syntax:           _IsInternet (  ) ; Parameter(s):     None. ; Return Value(s):  Success: Returns 1. ;                   Failure: Returns 0 and sets the @error flag to non-zero. @extended flag will contain the error code ;                            are specific to the WinINet functions. ; ; Author(s):        Yashied ; Note(s):          - ;==================================================================================================================================== func _IsInternet()         local $Ret = DllCall($WININET_DLL, 'int', 'InternetGetConnectedState', 'dword*', 0x20, 'dword', 0)         if (@error) then         return SetError(1, 0, 0)     endif         local $wError = _WinAPI_GetLastError()         return SetError((not ($wError = 0)), $wError, $Ret[0]) endfunc; _IsInternet #EndRegion Public Functions

Attached File  FTP.au3   58.01KB   2108 downloads
Attached File  WinINetErrorMessages.au3   5.18KB   885 downloads

Example1
AutoIt         
#Include <FTP.au3> const $Host = 'ftp.mozilla.org' const $Login = '' const $Password = '' local $hFtp, $hSession, $hFile, $tBuffer, $nSize, $nBytes _FTP_Startup() $hFtp = _FTP_Open('MyFtp') $hSession = _FTP_Connect($hFtp, $Host, $Login, $Password) $hFile = _FTP_OpenFile($hSession, 'README') $nSize = _FTP_GetFileSize($hFile) $tBuffer = DllStructCreate('byte[' & $nSize & ']') _FTP_ReadFile($hFile, $tBuffer, $nSize) _FTP_CloseFile($hFile) $hFile = _WinAPI_CreateFile('README', 1) _WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), $nSize, $nBytes) _WinAPI_CloseHandle($hFile) _FTP_Disconnect($hSession) _FTP_Close($hFtp) _FTP_Shutdown()


Example2
AutoIt         
#Include <FTP.au3> const $Host = 'ftp.mozilla.org' const $Login = '' const $Password = '' local $hFtp, $hSession, $hFind, $tFind _FTP_Startup() $hFtp = _FTP_Open('MyFtp') $hSession = _FTP_Connect($hFtp, $Host, $Login, $Password) $tFind = DllStructCreate($tagWIN32_FIND_DATA) $hFind = _FTP_FileFindFirst($hSession, '', $tFind) while not @error     ConsoleWrite(DllStructGetData($tFind, 'FileName') & @CR)     _FTP_FileFindNext($hFind, $tFind) wend _FTP_FileFindClose($hFind)     _FTP_Disconnect($hSession) _FTP_Close($hFtp) _FTP_Shutdown()








#2 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,409 posts

Posted 01 May 2009 - 06:23 PM

Look here:


http://www.autoitscript.com/trac/autoit/ticket/271

Completed Feature Requests (Sorted by Milestone)
FTP - make it as standard include file (or native AutoIt)
Added in version: 3.3.1.0

Edited by Zedna, 01 May 2009 - 06:24 PM.


#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,513 posts

Posted 01 May 2009 - 06:39 PM

Look here:


http://www.autoitscript.com/trac/autoit/ticket/271

Completed Feature Requests (Sorted by Milestone)
FTP - make it as standard include file (or native AutoIt)
Added in version: 3.3.1.0

It would be great. But now I'm using this UDF, and decided to share them.

EDIT: I think it would be good to build in AutoIt function InetPut() (in their own threads) like InetGet().

Edited by Yashied, 01 May 2009 - 06:47 PM.


#4 Splash

Splash

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 10 June 2009 - 12:42 AM

Nice man!!!

#5 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,513 posts

Posted 10 June 2009 - 07:21 AM

196 :D downloads and only 2 :D replies?

;)

Edited by Yashied, 10 June 2009 - 07:23 AM.


#6 myspacee

myspacee

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 649 posts

Posted 10 June 2009 - 09:18 AM

Nice !
find your version more simple to use :D

Can you post some code for most common operation ?
(_FTP_GetFile, _FTP_putFile, etc)

good job,

m.

Edited by myspacee, 10 June 2009 - 09:25 AM.


#7 Splash

Splash

    Wayfarer

  • Active Members
  • Pip
  • 76 posts

Posted 10 June 2009 - 04:00 PM

@myspacee:
read the code comments :D

#8 Xwolf

Xwolf

    Seeker

  • Active Members
  • 40 posts

Posted 29 October 2009 - 08:26 AM

Good jobs.
Thanks.

#9 wwant

wwant

    Seeker

  • New Members
  • 2 posts

Posted 08 December 2009 - 01:08 AM

Good Job

#10 Shiro

Shiro

    Wayfarer

  • Banned (NOT IN USE)
  • 87 posts

Posted 14 June 2010 - 08:27 PM

where i have to put the location of my zip file which i want to upload?
Posted Image

#11 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,513 posts

Posted 14 June 2010 - 09:18 PM

where i have to put the location of my zip file which i want to upload?

C:\Data\Game17\G3\Uploaded\

#12 Shiro

Shiro

    Wayfarer

  • Banned (NOT IN USE)
  • 87 posts

Posted 15 June 2010 - 09:48 AM

it's not working for me.
i just want to upload a file.
here is what i tried...
#Include  <FTP.au3> const $Host = 'ftp.fadelsalehco.com' const $Login = 'root_1' const $Password = '*******' local $hFtp, $hSession, $hFile, $tBuffer, $nSize, $nBytes _FTP_Startup() $hFtp = _FTP_Open('MyFtp') $hSession = _FTP_Connect($hFtp, $Host, $Login, $Password) _FTP_PutFile($hSession, "c:\web\index.php", "public_html\index.php", $lFlags = INTERNET_FLAG_TRANSFER_BINARY, $lContext = 0) _FTP_Disconnect($hSession) _FTP_Close($hFtp) _FTP_Shutdown()

Posted Image

#13 NewTester

NewTester

    Seeker

  • Active Members
  • 9 posts

Posted 20 July 2010 - 02:25 AM

hey guys, uploading to ftp using Putftp() seems to be working fine...........but please let me know how to download files from FTP because _FTP_FileGet is not working for me,every time i get return value as 0


please help me as this is very very urgent requirement




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users