[英]Batch file to Copy files (name_date) from FTP server to local directory?
I want to create a batch file, including the following functions: 我想创建一个包含以下功能的批处理文件:
Connection to a FTP server
Copying the files from there to a local directory (just today file named: product_yyyymmdd_hour.csv)
I haven't done that much with batch files so far, so it would be great if you could help me. 到目前为止,我对批处理文件还没有做太多事情,因此,如果您能帮助我,那将是很好的。 I know there is the ftp command, and I know how to connect at ftp, but unfortunately I don't know how to copy those file.
我知道这里有ftp命令,而且我知道如何在ftp上进行连接,但是不幸的是,我不知道如何复制那些文件。 very day I must copy only today file.
那天我必须只复制今天的文件。 for example: Product_20120611_1233.csv Product_20120612_1115.csv etc. The source folder an destination folder are the same every day, just the file name is different.
例如:Product_20120611_1233.csv Product_20120612_1115.csv等。源文件夹和目标文件夹每天都相同,只是文件名不同。 Thanks a lot for your help!
非常感谢你的帮助!
If you want to indicate the today date in batch you have to format it first. 如果要批量指定今天的日期,则必须先格式化它。 It depends on the date-format you use on your computer.
这取决于您在计算机上使用的日期格式。
For example in an Italian format it will be dd/MM/yyyy, in the American one it will be MM/dd/yyyy. 例如,意大利格式为dd / MM / yyyy,美国格式为MM / dd / yyyy。
Italian: 意大利语:
SET "day=%date:~-10,2%"
SET "month=%date:~-7,2%"
SET "year=%date:~-4%"
SET "dateStamp=%year%%month%%day%"
American: 美国:
SET "day=%date:~-7,2%"
SET "month=%date:~-10,2%"
SET "year=%date:~-4%"
SET "dateStamp=%year%%month%%day%"
Once you made this, you can specify the file name in a few ways, EG 完成此操作后,您可以通过几种方式指定文件名,例如EG
SET "fileName=Product_%dateStamp%_*.csv"
Now, you can do a copy in this way: 现在,您可以通过以下方式进行复制:
FOR %%f IN (%yourPath%\%fileName%) DO (
COPY %%f %whereToCopy%
)
I don't know how it works in a ftp-script, but you can always change the script you found. 我不知道它在ftp脚本中如何工作,但是您始终可以更改找到的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.