找回密码
 加入
搜索
查看: 1879|回复: 2

[系统综合]  求一个 ftp的文件检查脚本

[复制链接]
发表于 2011-12-20 10:05:10 | 显示全部楼层 |阅读模式
本帖最后由 twomax 于 2011-12-20 10:06 编辑

求一个 ftp的文件检查脚本

当前知道可以用FileExists 取得文件是否存在,但小弟只会在本机端使用,且GUI 的语法还不太用使用,想求先进前辈指导一下,
不需download 只作检查ftp中的文件是否存即可,:例如ftp下有 三个文件档 a.txt b.txt c.txt  ,a.txt , b.txt 存在即显示a.txt b.txt 存在,
c.txt不存在 就不用显示,如有GUI 腳本的更好
发表于 2011-12-23 11:46:00 | 显示全部楼层
本帖最后由 xiehuahere 于 2011-12-23 11:49 编辑

给个代码片段,你参考一下吧。
用的时候直接调用FtpFileExists函数即可。
当然你也可以把 $remoteDir 和 $remoteFileName 这两个参数结合为一个参数 $RemoreFileFullPath,然后在函数里面解析出路径和文件名。
Const $server = '172.16.0.11'
Const $username = 'root'
Const $password = '123456'

;============================================================================
; Function Name: FtpFileExists
; Return value: 0 - Not exist
;                1 - Exist
;                 -1 - Function returns fail
;============================================================================
Func FtpFileExists($remoteDir, $remoteFileName)
        Local $h_Handle

        $Open = _FTP_Open('myFTP')
        $Conn = _FTP_Connect($Open, $server, $username, $password)
        If @error <> 0 Then Return -1

        $aFile = _FTP_FindFileFirst($Conn, $remoteDir, $h_Handle)
        If @error <> 0 Then Return -1

        While $aFile[10] <> $remoteFileName        ; $aFile[10]: File Name
                $aFile = _FTP_FindFileNext($h_Handle)
                If @error <> 0 Then        ;Finish file searching and not found
                        _FTP_FindFileClose($h_Handle)
                        _FTP_Close($Conn)
                        Return 0
                EndIf
        WEnd

        _FTP_FindFileClose($h_Handle)
        _FTP_Close($Conn)
        Return 1
EndFunc
 楼主| 发表于 2011-12-23 20:37:48 | 显示全部楼层
感謝2樓大大分享,來試一下看看
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-20 19:31 , Processed in 0.095192 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表