gpt4 book ai didi

Windows 批处理文件 - 仅将最新文件上传到 FTP

转载 作者:可可西里 更新时间:2023-11-01 09:19:31 27 4
gpt4 key购买 nike

我想执行从 Windows 服务器到我的 FTP 的自动文件传输。

问题是生成的文件名称中带有时间戳(名称不固定)。所以我只需要上传文件的最后一个版本(最新)(基于实际文件时间戳,而不是名称中的时间戳)。有什么办法吗?

在 Windows Server 2003 下运行。谢谢。

最佳答案

要选择 Windows 批处理文件中的最新文件,请参阅
How do I write a Windows batch script to copy the newest file from a directory?

在此基础上,您可以创建一个上传批处理文件,例如:

@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

要获得更简单、更可靠的方法,请使用一些功能更强大的第 3 方 FTP 客户端。

例如 WinSCP FTP client , 您可以使用 -latest switch它的put command .

示例批处理文件(.bat):

winscp.com /ini=nul /command ^
"open ftp://username:password@ftp.example.com/" ^
"put -latest C:\source\path\* /target/path/" ^
"exit"

你甚至可以拥有 WinSCP generate the script/batch file for you (您只需要手动添加 -latest 开关)。

参见 WinSCP article on Uploading the most recent file .

(我是 WinSCP 的作者)

关于Windows 批处理文件 - 仅将最新文件上传到 FTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39971561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com