我正在尝试将 XML 文件从 FTP 位置复制到应用程序服务器 - 但不是所有文件。新文件每半小时在 ftp 位置存档一次。我只需要根据时间戳和日期传输新文件。
我目前正在使用以下 2 个文件从 FTP 位置复制所有文件。
批处理文件:
ftp -i -s:D:\ftp_commands.txt -n <host name>
文本文件 (ftp_commands.txt):
user <username> <password>
cd <source path>
lcd <destination path>
mget *
bye
谁能帮我根据时间戳或日期复制文件?
最佳答案
使用 Windows 批处理文件和内置 FTP 客户端 (ftp.exe
) 来实现是一项相当复杂的任务。
使用 PowerShell 或其他更强大的语言会更容易。
使用功能更强大的 FTP 客户端更容易。
例如WinSCP FTP client支持时间限制。
使用 WinSCP,下载今天的文件的批处理文件就像:
winscp.com /ini=nul /log=todays.log /command ^
"open ftp://username:password@ftp.example.com/" ^
"get /remote/path/*>=%%TIMESTAMP#yyyy-mm-dd%% C:\local\path\" ^
"exit"
使用 WinSCP 5.13 和更新版本,语法更简单:
"get /remote/path/*>=today C:\local\path\" ^
这使用了 %TIMESTAMP%
syntax和一个 file mask with a time-constraint .
另见:
(我是 WinSCP 的作者)
关于windows - 使用 Windows 批处理文件从 FTP 服务器仅下载今天的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44663446/