批处理文件将文件(name_date)从FTP服务器复制到本地目录?

时间:2021-02-17 16:02:27

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. 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. Thanks a lot for your help!

到目前为止,我还没有对批处理文件做过那么多,所以如果你能帮助我会很棒。我知道有ftp命令,我知道如何在ftp连接,但不幸的是我不知道如何复制这些文件。那天我必须只复制今天的文件。例如:Product_20120611_1233.csv Product_20120612_1115.csv等。目标文件夹的源文件夹每天都相同,只是文件名不同。非常感谢你的帮助!

1 个解决方案

#1


0  

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, E.G.

完成此操作后,您可以通过几种方式指定文件名,E.G。

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脚本中的工作原理,但您可以随时更改找到的脚本。

#1


0  

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, E.G.

完成此操作后,您可以通过几种方式指定文件名,E.G。

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脚本中的工作原理,但您可以随时更改找到的脚本。