argumentum

Example of _FTP_GetLastResponseInfo() and _FTP_Command()

1 post in this topic

#1 ·  Posted (edited)

I spent a lot of time looking for an example. When I finally figure it out. It was simple.
So, here is an example for the next desperate soul trying to make sense of it.

#include <FTPEx.au3>
#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <Debug.au3>

; this is to show how _FTP_Command() and  _FTP_GetLastResponseInfo() can be used.

_DebugSetup(StringTrimRight(@ScriptName, StringLen(".exe")) & ' example', True)

Local $sServer = 'ftp.uconn.edu' ; ..found at "https://dlptest.com/ftp-test/"
Local $sUsername = ''
Local $sPass = ''
Local $iError, $sMessage

Local $hOpen = _FTP_Open('MyFTP Control')
If Not @error Then
    Local $pCallback = _FTP_SetStatusCallback($hOpen, 'FTPStatusCallbackHandler')
    _FTP_GetLastResponseInfo($iError, $sMessage)
    _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
    Local $hConn = _FTP_Connect($hOpen, $sServer, $sUsername, $sPass, 0, $INTERNET_DEFAULT_FTP_PORT, $INTERNET_SERVICE_FTP, 0, $pCallback)
    If Not @error Then
        _FTP_GetLastResponseInfo($iError, $sMessage)
        _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
        Local $aFile = _FTP_ListToArrayEx($hConn, 0)
        If Not @error Then
            _FTP_GetLastResponseInfo($iError, $sMessage)
            _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
            $aFile[0][1] = "Filesize"
            $aFile[0][2] = "FileAttribute"
            $aFile[0][3] = "File Modification datetime"
            $aFile[0][4] = "File Creation datetime"
            $aFile[0][5] = "File Access datetime"
            For $n = 1 To UBound($aFile) - 1
                $aFile[$n][2] = $aFile[$n][2] & " [" & FtpAttribute2Str($aFile[$n][2]) & "]"
            Next
            _DebugOut(">=============" & @CRLF & _SQLite_Display2DResult($aFile, 0, True) & @CRLF & "=============<" & @CRLF)
        Else
            MsgBox($MB_SYSTEMMODAL, "Error", '_FTP_ListToArrayEx($Conn, 0)' & @CRLF & _
                    '@error = ' & @error & ' @extended = ' & @extended)
        EndIf
        Local $hcmd = _FTP_Command($hConn, 'STAT' & @CRLF, $FTP_TRANSFER_TYPE_ASCII, 0) ; or SYST, HELP, etc.
        _FTP_GetLastResponseInfo($iError, $sMessage)
        _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
        Sleep(100)

        Local $iFtpc = _FTP_Close($hConn)
        _FTP_GetLastResponseInfo($iError, $sMessage)
        _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
    Else
        _FTP_GetLastResponseInfo($iError, $sMessage)
        _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
        MsgBox($MB_SYSTEMMODAL, "Error", '_FTP_Connect($Open, ' & $sServer & ', ' & $sUsername & ', ' & $sPass & ')' & @CRLF & _
                '@error = ' & @error & ' @extended = ' & @extended)
    EndIf
    Local $iFtpo = _FTP_Close($hOpen)
    _FTP_GetLastResponseInfo($iError, $sMessage)
    _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
Else
    _FTP_GetLastResponseInfo($iError, $sMessage)
    _DebugOut(">=============" & @CRLF & $sMessage & @CRLF & "=============<" & @CRLF)
    MsgBox($MB_SYSTEMMODAL, "Error", "_FTP_Open('MyFTP Control')" & @CRLF & _
            '@error = ' & @error & ' @extended = ' & @extended)
EndIf

Func FTPStatusCallbackHandler($hInternet, $iContext, $iInternetStatus, $pStatusInformation, $iStatusInformationLength)
    #forceref $hInternet, $iContext
    If $iInternetStatus = $INTERNET_STATUS_REQUEST_SENT Or $iInternetStatus = $INTERNET_STATUS_RESPONSE_RECEIVED Then
        Local $iBytesRead
        Local $tStatus = DllStructCreate('dword')
        _WinAPI_ReadProcessMemory(_WinAPI_GetCurrentProcess(), $pStatusInformation, $tStatus, $iStatusInformationLength, $iBytesRead)
        _DebugOut(_FTP_DecodeInternetStatus($iInternetStatus) & ' | Size = ' & DllStructGetData($tStatus, 1) & ' Bytes    Bytes read = ' & $iBytesRead)
    Else
        _DebugOut(_FTP_DecodeInternetStatus($iInternetStatus))
    EndIf
EndFunc   ;==>FTPStatusCallbackHandler

Func FtpAttribute2Str($i)
    Local Static $a[12][2]
    $a[0][0] = 11
    $a[1][0] = 0x01
    $a[1][1] = "R" ; FILE_ATTRIBUTE_READONLY
    $a[2][0] = 0x02
    $a[2][1] = "H" ; FILE_ATTRIBUTE_HIDDEN
    $a[3][0] = 0x04
    $a[3][1] = "S" ; FILE_ATTRIBUTE_SYSTEM
    $a[4][0] = 0x10
    $a[4][1] = "D" ; FILE_ATTRIBUTE_DIRECTORY
    $a[5][0] = 0x20
    $a[5][1] = "A" ; FILE_ATTRIBUTE_ARCHIVE
    $a[6][0] = 0x80
    $a[6][1] = "N" ; FILE_ATTRIBUTE_NORMAL
    $a[7][0] = 0x0100
    $a[7][1] = "T" ; FILE_ATTRIBUTE_TEMPORARY
    $a[8][0] = 0x0800
    $a[8][1] = "C" ; FILE_ATTRIBUTE_COMPRESSED
    $a[9][0] = 0x1000
    $a[9][1] = "O" ; FILE_ATTRIBUTE_OFFLINE
    $a[10][0] = 0x2000
    $a[10][1] = "I" ; FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
    $a[11][0] = 0x4000
    $a[11][1] = "E" ; $FILE_ATTRIBUTE_ENCRYPTED
    Local $n, $s = ""
    For $n = 1 To 11
        If BitAND($i, $a[$n][0]) = $a[$n][0] Then
            $s &= $a[$n][1]
        Else
            $s &= "."
        EndIf
    Next
    Return $s
EndFunc   ;==>FtpAttribute2Str

Hope this helps.

Edited by argumentum
fixed the code a bit

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now