Sign in to follow this  
Followers 0
grasshopper3

FTP scan sub-dir

3 posts in this topic

Can someone tell help me with this...

I am trying to get this script to go through a FTP site and get me a list of files in all directories. It doesn't go any deeper than the first sub-dir.

Func ScanFolders($SourceFolder, $Name)
    Local $FileArray,$FullFilePath, $hSearch2
    MsgBox(0,'$SourceFolder',$SourceFolder & "\*.*")
    $FileArray = _FTP_FindFileFirst($Conn, $SourceFolder & "\*.*", $hSearch2) ;$FileArray = _FTP_FindFileFirst($Conn, $SourceFolder & "\*", $hSearch2)
;~  _ArrayDisplay($FileArray)
    IF $FileArray[0] = 0  or @error = -1 Then
        _FTP_FindFileClose($hSearch2)
    Else
        $FullFilePath = $SourceFolder & "\" & $FileArray[10]
        
        If $FileArray[1] = 16 Then
            ScanFolders($FullFilePath, $Name)
        Else
            EmailBody($FullFilePath, $FileArray[10], $Name, $FileArray[6])
        EndIf
        
        While 1 
            $FileArray = _FTP_FindFileNext($hSearch2)
;~          _ArrayDisplay($FileArray)
            IF $FileArray[0] = 0 Then
                ExitLoop
            EndIf
            
            $FullFilePath = $SourceFolder & "\" & $FileArray[10]
            
            If $FileArray[1] = 16 Then
                ScanFolders($FullFilePath, $Name)
            Else
                EmailBody($FullFilePath, $FileArray[10], $Name, $FileArray[6])
            EndIf
        WEnd
    EndIf
    _FTP_FindFileClose($hSearch2)
    Return

Share this post


Link to post
Share on other sites



Only one search per session.

#Include <FTPEx.au3>

_FTP_Search('', 'ftp.mozilla.org')

Func _FTP_Search($sRemotePath, $sHost, $sLogin = '', $sPassword = '', $iPassive = 1, $iPort = 0)

    Local $hFtp, $hSession, $aFind, $hFind, $Result = 1

    $hFtp = _FTP_Open('MyFtp')
    $hSession = _FTP_Connect($hFtp, $sHost, $sLogin, $sPassword, $iPassive, $iPort)
    $aFind = _FTP_FindFileFirst($hSession, $sRemotePath, $hFind)
    While Not @error
        If BitAND($aFind[1], $FILE_ATTRIBUTE_DIRECTORY) Then
            If Not _FTP_Search($sRemotePath & '/' & $aFind[10], $sHost, $sLogin, $sPassword, $iPassive, $iPort) Then
                Return 0
            EndIf
        Else
            ConsoleWrite($sRemotePath & '/' & $aFind[10] & @CR)
        EndIf
        $aFind = _FTP_FindFileNext($hFind)
    WEnd
    _FTP_FindFileClose($hFind)
    _FTP_Close($hFtp)
    Return $Result
EndFunc   ;==>_FTP_Search

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks! I got it working.

Only one search per session.

#Include <FTPEx.au3>

_FTP_Search('', 'ftp.mozilla.org')

Func _FTP_Search($sRemotePath, $sHost, $sLogin = '', $sPassword = '', $iPassive = 1, $iPort = 0)

    Local $hFtp, $hSession, $aFind, $hFind, $Result = 1

    $hFtp = _FTP_Open('MyFtp')
    $hSession = _FTP_Connect($hFtp, $sHost, $sLogin, $sPassword, $iPassive, $iPort)
    $aFind = _FTP_FindFileFirst($hSession, $sRemotePath, $hFind)
    While Not @error
        If BitAND($aFind[1], $FILE_ATTRIBUTE_DIRECTORY) Then
            If Not _FTP_Search($sRemotePath & '/' & $aFind[10], $sHost, $sLogin, $sPassword, $iPassive, $iPort) Then
                Return 0
            EndIf
        Else
            ConsoleWrite($sRemotePath & '/' & $aFind[10] & @CR)
        EndIf
        $aFind = _FTP_FindFileNext($hFind)
    WEnd
    _FTP_FindFileClose($hFind)
    _FTP_Close($hFtp)
    Return $Result
EndFunc   ;==>_FTP_Search

Edited by grasshopper3

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
Sign in to follow this  
Followers 0