Windows批处理文件 - 只上传最新文件到FTP [英] Windows batch file - Upload only latest file to FTP
问题描述
问题在于该文件是在其名称中使用时间戳生成的(名称不是固定的)。所以我只需要上传文件的最后一个版本(最新版本)。有没有办法如何做到这一点?
在Windows Server 2003下运行。谢谢。
解决方案方案要选择Windows批处理文件中的最新文件,请参阅
我如何编写Windows批处理脚本从目录中复制最新的文件?
基于此,您可以创建上传批处理文件,如:
@echo off
FOR / F %% I IN('DIR C:\source\path\ *。* / B / O:D')DO SET NEWEST_FILE = %% I
echo上传%NEWEST_FILE%
(
echo open ftp.example。 com
echo username
echo password
echo put C:\source\path\%NEWEST_FILE%/ target / path /%NEWEST_FILE%
echo bye
)> ftp.txt
ftp.exe -s:ftp.txt
要获得更简单,更可靠的方法,请使用一些功能更强大的第三方FTP客户端。 WinSCP FTP客户端,您可以使用 -latest
开关的 put
命令。
$ b
一个批处理文件( .bat
):
winscp.com / ini = nul /命令^
打开ftp://用户名:password@ftp.example.com/^
put -latest C:\source\path\*/target/path/^
exit
您甚至可以使用 WinSCP为你生成脚本/批处理文件(y ou只需手动添加 -latest
开关。)
请参阅上传最新文件的WinSCP文章。是WinSCP的作者)
I want to do an automatic file transfer from Windows server to my FTP.
Problem is that file is generated with timestamp in its name (the name is not fixed). So I need to upload always only the last version (newest) of file. Is there any way how to do that?
Running under Windows Server 2003. Thank you.
To select the newest file in a Windows batch file, see
How do I write a Windows batch script to copy the newest file from a directory?
Based on that you can create an upload batch file like:
@echo off
FOR /F %%I IN ('DIR C:\source\path\*.* /B /O:D') DO SET NEWEST_FILE=%%I
echo Uploading %NEWEST_FILE%
(
echo open ftp.example.com
echo username
echo password
echo put C:\source\path\%NEWEST_FILE% /target/path/%NEWEST_FILE%
echo bye
) > ftp.txt
ftp.exe -s:ftp.txt
For an easier and more reliable approach, use some more powerful 3rd party FTP client.
For example with WinSCP FTP client, you can use the -latest
switch of its put
command.
An example batch file (.bat
):
winscp.com /ini=nul /command ^
"open ftp://username:password@ftp.example.com/" ^
"put -latest C:\source\path\* /target/path/" ^
"exit"
You can even have WinSCP generate the script/batch file for you (you just need to add the -latest
switch manually).
See WinSCP article on Uploading the most recent file.
(I'm the author of WinSCP)
这篇关于Windows批处理文件 - 只上传最新文件到FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!