简体   繁体   中英

Batch file to download a file from FTP

i want to download the "abcd.txt" file 'n' times with step of 2 mins. Following is the batch (with ftp script in it) file i've created to download a file from 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. 2) I dont know how to restrict it to download only 'n' times.

Any help! Thanks!

PING can be used to delay execution for a number of seconds. If specified (-w switch), PING will wait for a number of milliseconds between two pings before giving a time-out.

ie PING 127.0.0.1 -n 6 for a 5 seconds delay. 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

Also you can use TIMEOUT 120 will delay execution of the next command by 120 seconds

And for running batch for n times you can do

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

The 1,1,n is decoded as:

(start,step,end)

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

You can use CHOICE 's timeout to wait:

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)

In addition to Kaushal's answer, if you're on Vista/7, you may use

TIMEOUT /T 120 /NOBREAK

instead of ping to have the script pause for 2 minutes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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