简体   繁体   English

批处理文件以将文件(名称_日期)从FTP服务器复制到本地目录?

[英]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.

相关问题 将文件从 FTP 服务器复制到本地目录? - Copy files from FTP server to local directory? 批处理脚本可将文件从本地目录移动到特定的ftp位置 - Batch script to move files from a local directory to a particular ftp location FTP将所有文件从目录复制到本地目录 - FTP copy all files from a directory to local directory 如何使用批处理文件将文件从本地系统复制到ftp服务器-Task Scheduler - How to copy file from local system to ftp server using Batch file- Task Scheduler 批处理文件将具有日期限制的多个.txt文件从多个目录复制到一个目录 - batch file copy multiple .txt files with date restrictions from multiple directories to one directory 批处理文件,将目录中的所有文件上传到FTP - Batch file to upload all files in directory to FTP 将批处理文件中的新文件从FTP服务器下载到Windows - Downloading new files from FTP server to Windows in a batch file 批处理文件,用于将文件从一台服务器复制到另一台服务器,并将远程目录添加到文件名中 - batch file to copy files from one server to other adding remote directory to filename in process 从FTP服务器获取文件并将其复制到UNC目录 - Get file from FTP server and copy it to UNC directory 批处理:如何根据文件名将文件复制到目录 - BATCH: How can I copy files to directory based on file name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM