Jump to content

_FTP_DirDelete isnt working


Lociz
 Share

Recommended Posts

_FTP_DirDelete isnt working

Here is my code:

#NoTrayIcon
#include <FTPEx.au3>
TraySetState(2)

$SERVER = '****************'
$NAME = '*******'
$PASS = '*******'

Connect()

Func Connect()
    $FTP = _FTP_Open('FTP')
    $FTP_CS = _FTP_Connect($FTP, $SERVER, $NAME, $PASS, 1)
    _FTP_DirDelete($FTP_CS, "/public_html/*****/users/hwd/")
    sleep(3600000)
    Connect()
EndFunc

i was tested _FTPRemoveDir func, but not work.

Here is _FTPRemoveDir func:

Func _FTPRemovedir($l_FTPSession, $sFTPDirectory)
    $rmdirgui = GUICreate("Deleting folder: " & $sFTPDirectory, 300, 200, -1, -1, -1, $WS_DLGFRAME)
    $rmdirtext = GUICtrlCreateInput("", 10, 10, 280, 180, $ES_MULTILINE + $ES_READONLY)
    GUISetState()
    Local $aFile, $hSearch, $sWorkingdir, $sFolderlist, $i, $bFirst, $aFolderStack[2] = [1, $sFTPDirectory]
    While $aFolderStack[0] > 0
        $sWorkingdir = $aFolderStack[$aFolderStack[0]]
        $aFolderStack[0] -= 1
        $aFile = _FTP_FindFileFirst($l_FTPSession, $sWorkingdir & '/*', $hSearch, $INTERNET_FLAG_NO_CACHE_WRITE)
        If Not @error Then
            $bFirst = True
            While 1
                If $bFirst = False Then
                    $aFile = _FTP_FindFileNext($hSearch)
                    If @error Then ExitLoop
                EndIf
                If $aFile[1] = 16 Then; If file is a directory we are going to add it to the stack of folders we need to go through
                    If $aFile[10] <> ".." And $aFile[10] <> "." Then
;~                      If StringInStr($aFile[10], " ") Then $aFile[10] = StringReplace($aFile[10], " ", "_")
                        $aFolderStack[0] += 1
                        If UBound($aFolderStack) <= $aFolderStack[0] Then ReDim $aFolderStack[UBound($aFolderStack) * 2]
                        $aFolderStack[$aFolderStack[0]] = $sWorkingdir & "/" & $aFile[10]
                        $sFolderlist &= $sWorkingdir & "/" & $aFile[10] & ';'; Here I am adding the folder to a list of directorys I need to delete later
                    EndIf
                Else; else we delete it
                    If StringInStr($aFile[10], "/./") = 0 And StringInStr($aFile[10], "/../") = 0 Then
                        _FTP_FileDelete($l_FTPSession, $sWorkingdir & "/" & $aFile[10])
                        GUICtrlSetData($rmdirtext, @CRLF & 'File: ' & $sWorkingdir & "/" & $aFile[10] & ' Deleted', "add")
                    Else
                        GUICtrlSetData($rmdirtext, @CRLF & 'File: ' & $sWorkingdir & "/" & $aFile[10] & ' Skipped (In higher DIR)', "add")
                    EndIf
                EndIf
                $bFirst = False
            WEnd
        EndIf
        _FTP_FindFileClose($hSearch)
    WEnd
    $aFolderStack = StringSplit(StringTrimRight($sFolderlist, 1), ';')
    For $i = $aFolderStack[0] To 1 Step -1 ;Here we delete all those empty folders from last to first
        _FTP_DirDelete($l_FTPSession, $aFolderStack[$i]) ;<--- This is the problem area.
;~      _FTP_Command($l_FTPSession, 'rmdir ' & $aFolderStack[$i])
        GUICtrlSetData($rmdirtext, @CRLF & 'Directory: ' & $aFolderStack[$i] & ' Deleted', "add") 
    Next
    _FTP_DirDelete($l_FTPSession, $sFTPDirectory);Delete the original directory
    GUIDelete($rmdirgui)
EndFunc   ;==>_FTPRemovedir
Edited by Muhammed
Link to comment
Share on other sites

  • Developers

You have not given much information on what you do see happening when it doesn't work.

do you get info in log field? ($rmdirtext)

are any files deleted?

are you sure you have the rights to delete files?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You have not given much information on what you do see happening when it doesn't work.

do you get info in log field? ($rmdirtext)

are any files deleted?

are you sure you have the rights to delete files?

Jos

I was say delete dir, not files.

Link to comment
Share on other sites

  • Developers

So, what information is shown in the GUI displayed by the Func?

As far as I understand the _FTPRemovedir() UDF, it will delete all files it finds in the directory you want to delete and then delete the actual directory.

A GUI is shown giving information about what the UDF is doing.

...and are you sure you are allowed to delete the files/directories on the FTP server?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

So, what information is shown in the GUI displayed by the Func?

As far as I understand the _FTPRemovedir() UDF, it will delete all files it finds in the directory you want to delete and then delete the actual directory.

A GUI is shown giving information about what the UDF is doing.

...and are you sure you are allowed to delete the files/directories on the FTP server?

Jos

Yes i have authority to delete the files/directories.

Connect FTP, but not deleted any files/directories.

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...