leon460 发表于 2011-11-21 20:32:37

用_FTP_DirDelete 无法删除含有子目录的ftp服务器上的文件夹

_FTP_DirDelete,,可以删除ftp 服务器上的空文件夹,但是无法删除,含有子文件夹和文件的目录,请问,有好用的udf么?
谢谢了

geshenggang4 发表于 2011-11-21 20:36:12

应该是可以的吧!请把源码放上!

xms77 发表于 2011-11-21 21:16:41

是不是FTP服务器设置的问题呢?不然这个函数应该不是出现这种现象吧!

leon460 发表于 2011-11-22 08:50:05

回复 2# geshenggang4 #include <FTPEx.au3>
#include "CoProc.au3"

While 1
        $iPidotherfuc = _CoProc("ftp")
        Sleep(10000)
WEnd       

Func ftp()       
        Dim $downftpfileflag
        Dim $fFailIfExists
        $server = '172.21.16.46'
        $username = 'wwxsawis'
        $pass = 'awis123'
       
        $Open = _FTP_Open('SlipFinder ftp ')
        $Conn = _FTP_Connect($Open, $server, $username, $pass)
        $aFile = _FTP_ListToArray($Conn, 2)                ;只找文件
        If IsArray($aFile) Then
                Sleep(2000)                        ;等待下,以防止机台产生数据中
                For $i= 1 To $aFile                               
                        $filegroup=StringSplit($aFile[$i],".")
                        ;MsgBox(0,"",$filegroup)
                        If $filegroup = "txt" Then                        ;如果是txt档,则下载此文件
                                $downftpfileflag=_FTP_FileGet($Conn,"/" & $aFile[$i] ,"C:\" & $aFile[$i], $fFailIfExists = False)        ;false为不覆盖
                                MsgBox(0,"上传标志",$downftpfileflag ,1)
                                If $downftpfileflag = 1 Then                 ;判断是否下载成功,成功即可删除
                                        _FTP_FileDelete($Conn, "/" & $aFile[$i])
                                        MsgBox(0,"文件夹名",$filegroup)
                                        _FTP_DirDelete($Conn, "/" & $filegroup)
                                        MsgBox(0,"","上传后删除啦",1)
                                Else                                ;如果下载不成功,
                                        ;MsgBox(0,"@error",@error,1)
                                        $downftpfileflag=_FTP_FileGet($Conn,"/" & $aFile[$i] ,"C:\" & $aFile[$i], $fFailIfExists = False)       
                                EndIf
                        Else                                         ;如果不是txt档,则直接删除
                                _FTP_FileDelete($Conn, "/" & $aFile[$i])
                                MsgBox(0,"","直接删除啦",1)
                        EndIf                               
                Next                       
        EndIf       
        $Ftpc = _FTP_Close($Open)       
EndFunc

leon460 发表于 2011-11-22 08:58:24

贴出官方某高手的贴,,经测试ok#include <FTPEx.au3>

$dir = '/4'
$server = '172.21.16.46'
$username = 'wwxsawis'
$pass = 'awis123'

$Open = _FTP_Open('test')
$Conn = _FTP_Connect($Open, $server, $username, $pass)
If Not @error Then ConsoleWrite('Connected!' & @CRLF)

_FTP_DirSetCurrent($Conn, '/StartDir/');Very Important to set the current dirctory to the directory that the folder you want to delete is in.
_FTPRemovedir($Conn, $dir)
_FTP_Close($Open)

Func _FTPRemovedir($l_FTPSession, $sFTPDirectory)
    Local $aFile, $hSearch, $sWorkingdir, $sFolderlist, $i, $bFirst, $aFolderStack =
    While $aFolderStack > 0
      $sWorkingdir = $aFolderStack[$aFolderStack]
      $aFolderStack -= 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 = 16 Then; If file is a directory we are going to add it to the stack of folders we need to go through
                  $aFolderStack += 1
                  If UBound($aFolderStack) <= $aFolderStack Then ReDim $aFolderStack
                  $aFolderStack[$aFolderStack] = $sWorkingdir & "/" & $aFile
                  $sFolderlist &= $sWorkingdir & "/" & $aFile & ';'; Here I am adding the folder to a list of directorys I need to delete later
                Else; else we delete it
                  _FTP_FileDelete($l_FTPSession, $sWorkingdir & "/" & $aFile)
                  ConsoleWrite('File: ' & $sWorkingdir & "/" & $aFile & ' Deleted' & @CRLF)
                EndIf
                $bFirst = False
            WEnd
      EndIf
      _FTP_FindFileClose($hSearch)
    WEnd
    $aFolderStack = StringSplit(StringTrimRight($sFolderlist, 1), ';')
    For $i = $aFolderStack To 1 Step -1 ;Here we delete all those empty folders from last to first
      _FTP_DirDelete($l_FTPSession, $aFolderStack[$i])
      ConsoleWrite('Directory: ' & $aFolderStack[$i] & ' Deleted' & @CRLF)
    Next
    _FTP_DirDelete($l_FTPSession, $sFTPDirectory);Delete the original directory
EndFunc   ;==>_FTPRemovedir
页: [1]
查看完整版本: 用_FTP_DirDelete 无法删除含有子目录的ftp服务器上的文件夹