在 FTP 上搜索文件

发布于 2025-01-04 13:41:40 字数 303 浏览 0 评论 0原文

我想使用 FTP 批处理脚本使用 if-exist filename -else 语句查找 FTP 上是否存在文件,如下所示:

ftp.txt open ftp.mysite.com
ftp.txt username
ftp.txt password
ftp.txt if exist filename (echo file exists) else (echo file doesn't exist)
ftp.txt quit
ftp -s:ftp.txt

上面的 if-exist 行不起作用。 还有其他方法可以搜索吗?

I want to find if a file exists at FTP using if-exist filename -else statement using FTP batch script which is as follows:

ftp.txt open ftp.mysite.com
ftp.txt username
ftp.txt password
ftp.txt if exist filename (echo file exists) else (echo file doesn't exist)
ftp.txt quit
ftp -s:ftp.txt

the if-exist line above does not work.
Is there any other way to search?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与风相奔跑 2025-01-11 13:41:40

不要执行 FTP 脚本中的逻辑。

从批处理文件调用 ftp.txt 脚本。在 ftp.txt 脚本中,只需对文件执行 GET 操作即可。如果该文件存在,它将被下载到本地目录。否则就不会了。调用 FTP 脚本后,使用标准 DOS 批处理命令检查本地目录中文件是否存在,即:

@echo off

:FETCHFILE
ftp -s:ftp.txt
IF EXIST filetocheckfor.txt (
   REM the file was there, so do something
) ELSE
   echo Trying again...
   REM ping "sleep" would go here
   GOTO FETCHFILE
)

如果您想在重试中建立延迟,请通过 ping 虚假 IP 地址来执行“睡眠”,如本文所述:
http://www.dullsharpness.com/ 2010/06/14/elapsed-timer-using-pure-ms-dos/

Don't do the logic in the FTP script.

Call the ftp.txt script from a batch file. Within your ftp.txt script, just do a GET on your file. If the file is there, it'll be downloaded to the local directory. Otherwise, it won't. After calling the FTP script, check the file's existence in your local directory using standard DOS batch commands, i.e.:

@echo off

:FETCHFILE
ftp -s:ftp.txt
IF EXIST filetocheckfor.txt (
   REM the file was there, so do something
) ELSE
   echo Trying again...
   REM ping "sleep" would go here
   GOTO FETCHFILE
)

If you want to build a delay into your retries, perform a "sleep" by pinging a bogus IP address, as described in this post:
http://www.dullsharpness.com/2010/06/14/elapsed-timer-using-pure-ms-dos/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文