#include <FTPEx.au3>
#include "CoProc.au3"
#include <misc.au3>
#include <Array.au3>
$sleeptime=IniRead(@ScriptDir & "\settings.ini","settings","runtime",20)
$savetime=IniRead(@ScriptDir & "\settings.ini","settings","savetime",7)
$server = IniRead(@ScriptDir & "\settings.ini","settings","server","")
$username = IniRead(@ScriptDir & "\settings.ini","settings","username","")
$pass = IniRead(@ScriptDir & "\settings.ini","settings","pass","")
$targetfilepath = IniRead(@ScriptDir & "\settings.ini","settings","targetfilepath","")
While 1
;$iPidotherfuc = _CoProc("ftp")
ftp()
Sleep($sleeptime*1000)
#CS If ProcessExists($iPidotherfuc) Then
ProcessClose($iPidotherfuc)
endif
#CE
WEnd
Func ftp()
;_Singleton("ftpfunc",0)
Dim $downftpfileflag
Dim $fFailIfExists
$i_Passive = 1
$Open = _FTP_Open('slip ftp ')
$Conn = _FTP_Connect($Open, $server, $username, $pass,$i_Passive);,$INTERNET_FLAG_NO_CACHE_WRITE, $INTERNET_FLAG_RELOAD, $INTERNET_FLAG_RESYNCHRONIZE)
If $Conn <> 0 Then
$aFile = _FTP_ListToArrayEx($Conn,0,$INTERNET_FLAG_NO_CACHE_WRITE, $INTERNET_FLAG_RELOAD, $INTERNET_FLAG_RESYNCHRONIZE) ;只找文件
;_ArrayDisplay($aFile,"文件夹与文件信息")
If IsArray($aFile) Then
Sleep(2000) ;等待下,以防止机台产生数据中
For $i= 1 To $aFile[0][0]
$sourcefile = "/" & $aFile[$i][0]
$targetfile = $targetfilepath & $aFile[$i][0]
$filegroup=StringSplit($aFile[$i][0],".")
If Not IsArray($filegroup) Then
ContinueLoop ;文件中没有符号 “.”,则判断是文件夹
Else
If $filegroup[0] >= 2 Then
If $filegroup[2] = "txt" Or $filegroup[2] = "tff" Then ;如果是txt档,则下载此文件
;MsgBox(0,FileGetSize($targetfilepath & $aFile[$i][0]),$aFile[$i][1],2)
If FileGetSize($targetfilepath & $aFile[$i][0]) < $aFile[$i][1] Then ;如果ftp服务器上的文件大于本地的文件,则上传
FileSetAttrib($targetfile,"-R")
$deleteflag=FileDelete($targetfile)
Sleep(200)
$downftpfileflag=_FTP_FileGet($Conn,$sourcefile,$targetfile, $fFailIfExists = False,$INTERNET_FLAG_TRANSFER_ASCII,$INTERNET_FLAG_RESYNCHRONIZE) ;false为不覆盖
;_FTP_FileDelete($Conn,$sourcefile)
;MsgBox(0,$sourcefile,$targetfile)
FileSetTime($targetfile,"",0);要更改的时间戳类型: 0 = 修改时间(默认), 1 = 创建时间, 2 = 访问时间
Else ;
;MsgBox(0,"",$targetfile)
$timearray=FileGetTime($targetfile)
If IsArray($timearray) Then
$localtime=$timearray[0] & $timearray[1] & $timearray[2]
$romotetime=$aFile[$i][3]
$romotetimemid=StringLeft($romotetime,10)
$romotetimemid1=StringSplit($romotetimemid,"/")
$romotetimeLast=$romotetimemid1[1] & $romotetimemid1[2] & $romotetimemid1[3]
$timediff=$romotetimeLast-$localtime
;MsgBox(0,$timediff,$savetime)
If $timediff >= $savetime Then
;MsgBox(0,"",$sourcefile)
;_FTP_FileDelete($Conn,$sourcefile)
_FTP_FileDelete($Conn,$aFile[$i][0])
;MsgBox(0,"",@error)
EndIf
EndIf
EndIf
endif
EndIf
EndIf
Next
EndIf
EndIf
$Ftpc = _FTP_Close($Open)
EndFunc