简体   繁体   English

批处理文件以从FTP下载文件

[英]Batch file to download a file from FTP

i want to download the "abcd.txt" file 'n' times with step of 2 mins. 我想以2分钟的步长下载“ abcd.txt”文件'n'次。 Following is the batch (with ftp script in it) file i've created to download a file from FTP. 以下是我创建的用于从FTP下载文件的批处理文件(包含ftp脚本)。

:DOWNLOAD_AGAIN
@ftp -i -s:"%~f0"&GOTO:DOWNLOAD_AGAIN
open 192.168.4.4
username
password
!:--- FTP commands below here ---
cd /data/
pwd
get abcd.txt
bye

The problem is, 1) Above batch file does not wait for 2 mins, it immediately starts downloading the file again. 问题是,1)上面的批处理文件没有等待2分钟,它立即开始再次下载文件。 2) I dont know how to restrict it to download only 'n' times. 2)我不知道如何限制它仅下载“ n”次。

Any help! 任何帮助! Thanks! 谢谢!

PING can be used to delay execution for a number of seconds. PING可用于延迟执行数秒。 If specified (-w switch), PING will wait for a number of milliseconds between two pings before giving a time-out. 如果指定(-w开关),PING将在两次ping之间等待毫秒数,然后给出超时。

ie PING 127.0.0.1 -n 6 for a 5 seconds delay. 即PING 127.0.0.1 -n 6延迟5秒。 or PING 1.1.1.1 -n 1 -w 60000 >NUL will delay execution of the next command 60 seconds, provided 1.1.1.1 is not a valid IP address 或PING 1.1.1.1 -n 1 -w 60000> NUL将延迟下一个命令的执行60秒,前提是1.1.1.1不是有效的IP地址

Also you can use TIMEOUT 120 will delay execution of the next command by 120 seconds 您也可以使用TIMEOUT 120将下一条命令的执行延迟120秒

And for running batch for n times you can do 对于n次运行批处理,您可以执行

FOR /L %i IN (1,1,n) DO (
       //to stuff
 )

The 1,1,n is decoded as: 1,1,n解码为:

(start,step,end) (启动,步骤,结束)

抓住Unix Utilities端口 ,那里有一个有用的sleep程序,它可以让您延迟脚本。

You can use CHOICE 's timeout to wait: 您可以使用CHOICE的超时来等待:

CHOICE /C XY /D X /T 120 > NUL

(offer a prompt choice of X or Y, default to X in 120 seconds & return, hide choice by directing to nul) (提供X或Y的即时选择,默认为120秒内X并返回,通过直接选择nul隐藏选择)

In addition to Kaushal's answer, if you're on Vista/7, you may use 除了Kaushal的答案外,如果您使用的是Vista / 7,则可以使用

TIMEOUT /T 120 /NOBREAK

instead of ping to have the script pause for 2 minutes. 而不是ping命令使脚本暂停2分钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM