_FTP_FileDelete 不能删除ftp上的文件[已解决]
本帖最后由 leon460 于 2011-12-20 10:45 编辑下载ftp文件没有问题了,但_FTP_FileDelete 不能删除ftp上的文件 不知道是哪里出错了,请帮忙看看,头昏脑涨中,,总觉得ftp相关函数不怎么好用,呵呵,没有本地操作文件来的方便
不好意思了,是服务器上的时间格式不对,{:face (394):}
以下是代码#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
$sourcefile = "/" & $aFile[$i]
$targetfile = $targetfilepath & $aFile[$i]
$filegroup=StringSplit($aFile[$i],".")
If Not IsArray($filegroup) Then
ContinueLoop ;文件中没有符号“.”,则判断是文件夹
Else
If$filegroup >= 2 Then
If$filegroup = "txt" Or $filegroup = "tff" Then ;如果是txt档,则下载此文件
;MsgBox(0,FileGetSize($targetfilepath & $aFile[$i]),$aFile[$i],2)
If FileGetSize($targetfilepath & $aFile[$i]) < $aFile[$i] 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 & $timearray & $timearray
$romotetime=$aFile[$i]
$romotetimemid=StringLeft($romotetime,10)
$romotetimemid1=StringSplit($romotetimemid,"/")
$romotetimeLast=$romotetimemid1 & $romotetimemid1 & $romotetimemid1
$timediff=$romotetimeLast-$localtime
;MsgBox(0,$timediff,$savetime)
If $timediff >= $savetimeThen
;MsgBox(0,"",$sourcefile)
;_FTP_FileDelete($Conn,$sourcefile)
_FTP_FileDelete($Conn,$aFile[$i])
;MsgBox(0,"",@error)
EndIf
EndIf
EndIf
endif
EndIf
EndIf
Next
EndIf
EndIf
$Ftpc = _FTP_Close($Open)
EndFunc 没条件做相关实验,帮你顶个
顺便问声,有删除权限吗?服务器相关权限开放没? 回复 2# user3000
权限没有问题,添加了删除相关的权限。 有最新发现:
我运行在win7 32bit enterprise就没有问题,但是运行在win2003 32bit 企业版 sp2下就不行,同样的程序哦
真是奇怪了
页:
[1]