Jump to content

problem with my FTPDelDirRecursive function


Recommended Posts

Hi,

First, Sorry for my bad english, I'm french.

I have write a function who delete all files and directory in a specified directory on FTP server.

But I have a problem, the loop don't work, Can you look my code ?

Code :

#include "ftp3.au3"

$server = 'my_ftp_server'
$username = 'my_username'
$pass = 'my_password'
$ftp_main_dir = '/exemple/'
$ftp_file_mask = '*.*'

$dllhandle = DllOpen('wininet.dll')
$Open = _FTPOpen('MyFTP Control')
If @error Then MsgBox(0, "error", "Open")
$Conn = _FTPConnect($Open, $server, $username, $pass)
If @error Then MsgBox(0, "error", "Connect")
FTPDelDirRecurse($ftp_main_dir)
_FTPClose($Open)
DllClose($dllhandle)


Func FTPDelDirRecurse($ftp_dir)

        Dim $Handle
        Dim $DllRect
       
        Local $FileInfo = _FtpFileFindFirst($Conn, $ftp_dir & $ftp_file_mask, $Handle, $DllRect)
        If $FileInfo[0] Then
            Do
               
;~         If current is directory
                If $FileInfo[1] == 16 And $FileInfo[10] <> "." And $FileInfo[10] <> ".." Then ; dir attrib = 16
                    MsgBox(0, "Current dir", $FileInfo[10])
                    Local $i = $ftp_dir & $FileInfo[10] & "/"
                    FTPDelDirRecurse($i)
                EndIf
               
;~     If current is file
                If $FileInfo[1] == 128 Then ; file attrib = 128
                    MsgBox(0, "Current file", $FileInfo[10])
                    _FTPDelFile($Conn, $ftp_dir & $FileInfo[10])
                EndIf
              
                $FileInfo = _FtpFileFindNext($Handle, $DllRect)
              
            Until Not $FileInfo[0]   
        EndIf
        _FtpFileFindClose($Handle, $DllRect)
       
EndFunc ;==> FTPDelDirRecurse
Edited by NeuroToxic
Link to comment
Share on other sites

Don't use DIM anywhere anymore. Declare explicitly for Global or Local. Specifically, change DIM to Local inside your function. I can't test, so I don't know if that impacts your function, but it stood out.

Also, everything your function needs from the global environment should be passed to it, not read from Global variables. You should pass $Conn and $ftp_file_mask as parameters (re-passing them in the recursive calls).

Third, is the mask "*.*" appropriate for what you want? I would have expected just "*" for FTP.

Hope that helps.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...