whi*_*bit 3 windows ftp batch-file
我想自动将文件从 Windows 服务器传输到我的 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 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
Run Code Online (Sandbox Code Playgroud)
要获得更简单、更可靠的方法,请使用一些更强大的第 3 方 FTP 客户端。
例如使用WinSCP FTP 客户端,您可以使用其命令的-latest开关。put
批处理文件示例 ( .bat):
winscp.com /ini=nul /command ^
"open ftp://username:password@ftp.example.com/" ^
"put -latest C:\source\path\* /target/path/" ^
"exit"
Run Code Online (Sandbox Code Playgroud)
您甚至可以让WinSCP 为您生成脚本/批处理文件(您只需-latest手动添加开关)。
(我是WinSCP的作者)