Sample code for 30+ languages & platforms
AutoIt

FTP Iterate over Files in Directory Matching ListPattern

See more RSA Examples

Uses the ListPattern property to iterate over the files in a directory matching the pattern.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oFtp = ObjCreate("Chilkat.Ftp2")

$oFtp.Hostname = "ftp.example.com"
$oFtp.Username = "my_login"
$oFtp.Password = "my_password"
$oFtp.Port = 21
$oFtp.AuthTls = True

$bSuccess = $oFtp.Connect()
If ($bSuccess <> True) Then
    ConsoleWrite($oFtp.LastErrorText & @CRLF)
    Exit
EndIf

; Change to the "images" sub-directory located under our FTP account's home directory.
$bSuccess = $oFtp.ChangeRemoteDir("images")
If ($bSuccess <> True) Then
    ConsoleWrite($oFtp.LastErrorText & @CRLF)
    Exit
EndIf

$oFtp.ListPattern = "*.png"

; Fetch the current remote directory contents by calling GetDirCount
Local $iN = $oFtp.GetDirCount()
If ($iN < 0) Then
    ConsoleWrite($oFtp.LastErrorText & @CRLF)
    Exit
EndIf

Local $i = 0
Local $sFilename
$oSbLocalPath = ObjCreate("Chilkat.StringBuilder")

While $i < $iN
    $sFilename = $oFtp.GetFilename($i)
    ConsoleWrite($sFilename & @CRLF)

    ; Download this file.
    $oSbLocalPath.SetString("qa_output/")
    $oSbLocalPath.Append($sFilename)
    $bSuccess = $oFtp.GetFile($sFilename,$oSbLocalPath.GetAsString())
    If ($bSuccess <> True) Then
        ConsoleWrite($oFtp.LastErrorText & @CRLF)
        Exit
    EndIf

    $i = $i + 1
Wend