Jump to content

FTP File Search


Recommended Posts

Hi,

I am trying to create a script that will be able to access multiple ftp sites and scan for files that have been modified in the last 24 hours then logs to an csv file. I have been able to find code that allows you to search through directories in windows explorer without the ftp. I have tried to modify this code to enable me to search through ftp files, but i am having trouble. Can someone help. Below is the code that I have so far.

This $list is a comma delimited list.

ScanRootFTP($list)

Func ScanRootFTP($DistrictList)
    Local $FileArray,$FullFilePath, $DistrictArray, $i = 1, $hSearch
    
    $DistrictArray = StringSplit($DistrictList, ",")
;~  _ArrayDisplay($DistrictArray)
    
    While $i <= UBound($DistrictArray)- 1
;~      MsgBox(0,'$DistrictArray[$i]',$DistrictArray[$i])
        $FileArray = _FTP_FindFileFirst($Conn, $DistrictArray[$i], $hSearch)
;~      _ArrayDisplay($FileArray)
        IF $FileArray[0] = 0 Then
            ExitLoop
        EndIf
    
        $FullFilePath = "/" & $DistrictArray[$i] & '/' & $FileArray[10]
;~      MsgBox(0,'$FullFilePath',$FullFilePath)
        If $FileArray[1] = 16 Then
;~              ScanFolders($FullFilePath, $DistrictArray[$i])
        Else
;~              eMailBody($FullFilePath)
;~              csvFile($FullFilePath, $FileArray[10], $DistrictArray[$i])
        EndIf
            
        While 1
            $FileArray = _FTP_FindFileNext($hSearch)
            
            IF $FileArray[0] = 0 Then
                ExitLoop
            EndIf
            
            $FullFilePath = "/" & $DistrictArray[$i] & '/' & $FileArray[10]
            If $FileArray[1] = 16 Then
;~              ScanFolders($FullFilePath, $DistrictArray[$i])
            Else
;~              eMailBody($FullFilePath)
;~              csvFile($FullFilePath, $FileArray[10], $DistrictArray[$i])
            EndIf
        WEnd
        $i += 1
;~      _FTP_FindFileClose($h_Handle)
    WEnd
    _FTP_FindFileClose($h_Handle)
    Return
EndFunc

Func ScanFolders($SourceFolder, $DistrictName)
    Local $FileArray,$FullFilePath, $hSearch
;~  MsgBox(0,'$SourceFolder',$SourceFolder)
    $FileArray = _FTP_FindFileFirst($Conn, $SourceFolder & "/*", $hSearch)
;~  _ArrayDisplay($FileArray)
            
    $FullFilePath = $SourceFolder & "/" & $FileArray[10]
    MsgBox(0,'\$FullFilePath',$FullFilePath)
    If $FileArray[1] = 16 Then
        ScanFolders($FullFilePath, $DistrictName)
    Else
;~          eMailBody($FullFilePath)
;~          csvFile($FullFilePath, $FileArray[10], $DistrictName)
    EndIf
    
    While 1 
        $FileArray = _FTP_FindFileNext($hSearch)
        IF $FileArray[0] = 0 Then
            ExitLoop
        EndIf
        
        $FullFilePath = $SourceFolder & "/" & $FileArray[10]
        MsgBox(0,'\$FullFilePath',$FullFilePath)
        If $FileArray[1] = 16 Then
            ScanFolders($FullFilePath, $DistrictName)
        Else
;~          eMailBody($FullFilePath)
;~          csvFile($FullFilePath, $FileArray[10], $DistrictName)
        EndIf
    WEnd
    _FTP_FindFileClose($h_Handle)
    Return
EndFunc
Link to comment
Share on other sites

I think that I have narrowed the problem down to this line...

$FileArray = _FTP_FindFileFirst($Conn, $DistrictArray[$i], $hSearch)

I can get it to read through the first directory and its sub-dir from my comma list, but it seems un-able to correctly get the first file from the second dir in the comma list.

_FTP_FindFileFirst($Conn, $DistrictArray[1], $hSearch) ----WORKS!

_FTP_FindFileFirst($Conn, $DistrictArray[2], $hSearch) ----DOESN'T WORK!

I did a _ArrayDisplay on $DistrictArray[2] and I am not sure what the results mean. Please interpret...

[0]|0x00000000 ----What does this mean?

[1]|0x00CC0008 ----What does this mean?

[2]|az-meza ----I know that [2] is the dir name.

[3]|0x01D7FD30 ----What does this mean?

[4]|0

[5]|0

Link to comment
Share on other sites

Solved my own problem. Here is my solution in case someone else wants to do it.

Func ScanRootFTP($DistrictList, $Conn)
    Local $FileArray,$FullFilePath, $DistrictArray, $i = 1, $hSearch
    
    $DistrictArray = StringSplit(StringStripWS($DistrictList,8), ",")
    
    While $i <= UBound($DistrictArray)- 1
        $FileArray = _FTP_FindFileFirst($Conn, $DistrictArray[$i], $hSearch)
        IF $FileArray[0] = 0  or @error = -1 Then
            _FTP_FindFileClose($hSearch)
            $i += 1
        Else
            $FullFilePath = "\" & $DistrictArray[$i] & '\' & $FileArray[10]
        
            If $FileArray[1] = 16 Then
                ScanFolders($FullFilePath, $DistrictArray[$i])
            Else
    ;~          eMailBody($FullFilePath)
    ;~          csvFile($FullFilePath, $FileArray[10], $DistrictArray[$i])
            EndIf
                
            While 1
                $FileArray = _FTP_FindFileNext($hSearch)
                
                IF $FileArray[0] = 0 Then
                    _FTP_FindFileClose($hSearch)
                    ExitLoop
                EndIf
                
                $FullFilePath = "\" & $DistrictArray[$i] & '\' & $FileArray[10]
                
                If $FileArray[1] = 16 Then
                    ScanFolders($FullFilePath, $DistrictArray[$i])
                Else
    ;~              eMailBody($FullFilePath)
                    csvFile($FullFilePath, $FileArray[10], $DistrictArray[$i])
                EndIf
            WEnd
            $i += 1
            _FTP_FindFileClose($hSearch)
        EndIf
    WEnd
    _FTP_FindFileClose($hSearch)
    Return
EndFunc
Link to comment
Share on other sites

Alright new question. How do I get the modified dates for ftp files? When I use "_FTP_FindFileFirst()" the date fields that are returned are "0". I am not sure what parameters to pass in for "_FTP_FileTimeLoHiToStr()". Can someone post some code examples or send me in the right direction? Thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...