#cs ____________________________________
#ce _______________脚本开始_________________
#include <FTPEx.au3>
#include "CoProc.au3"
#include <misc.au3>
$iPidotherfuc = _CoProc("_ftp")
While 1
;ftp()
Sleep(500)
#CS If ProcessExists($iPidotherfuc) Then
ProcessClose($iPidotherfuc)
endif
#CE
WEnd
func _ftp()
while 1
ftp()
Sleep(10000)
wend
endfunc
Func ftp()
_Singleton("ftpfunc",0)
Dim $downftpfileflag
Dim $fFailIfExists
;$server = ''
$server = ''
$username = 's1'
$pass = 'fin23'
$Open = _FTP_Open('SlipFinder ftp ')
$Conn = _FTP_Connect($Open, $server, $username, $pass)
;MsgBox(0,"$Conn",_FTP_DirGetCurrent($Conn),1)
If $Conn <> 0 Then
$aFile = _FTP_ListToArray($Conn, 2) ;只找文件
If IsArray($aFile) Then
Sleep(2000) ;等待下,以防止机台产生数据中
For $i= 1 To $aFile[0]
;MsgBox(0,"",$aFile[$i],1)
$sourcefile = "/" & $aFile[$i]
$targetfile = "C:\Slip\" & $aFile[$i]
;$filegroup=StringSplit($aFile[$i],".")
;MsgBox(0,"",$filegroup[2])
;If $filegroup[2] = "txt" Then ;如果是txt档,则下载此文件
$downftpfileflag=_FTP_FileGet($Conn,$sourcefile,$targetfile, $fFailIfExists = False,0,$INTERNET_FLAG_TRANSFER_ASCII) ;false为不覆盖
;MsgBox(0,"上传标志",$downftpfileflag ,1)
If $downftpfileflag = 1 Then ;判断是否下载成功,成功即可删除
_FTP_FileDelete($Conn, "/" & $aFile[$i])
;MsgBox(0,"文件夹名",$filegroup[1])
;_FTPRemovedir($Conn, "/" & $filegroup[1]) ; 删除产生的文件夹
;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
EndIf
$Ftpc = _FTP_Close($Open)
EndFunc
Func _FTPRemovedir($l_FTPSession, $sFTPDirectory)
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
$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
Else; else we delete it
_FTP_FileDelete($l_FTPSession, $sWorkingdir & "/" & $aFile[10])
ConsoleWrite('File: ' & $sWorkingdir & "/" & $aFile[10] & ' Deleted' & @CRLF)
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])
ConsoleWrite('Directory: ' & $aFolderStack[$i] & ' Deleted' & @CRLF)
Next
_FTP_DirDelete($l_FTPSession, $sFTPDirectory);Delete the original directory
EndFunc ;==>_FTPRemovedir
你要会变更啊,其实很容易理解的. |