Windows 批处理文件 - 仅将最新文件上传到 FTP [英] Windows batch file - Upload only latest file to FTP

查看:29
本文介绍了Windows 批处理文件 - 仅将最新文件上传到 FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件从 Windows 服务器自动传输到我的 FTP.

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 (based on the actual file timestamp, not timestamp in the name). Is there any way how to do that?

在 Windows Server 2003 下运行.谢谢.

Running under Windows Server 2003. Thank you.

推荐答案

要选择 Windows 批处理文件中的最新文件,请参阅
如何编写 Windows 批处理脚本来复制目录中的最新文件?

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:sourcepath*.* /B /O:D') DO SET NEWEST_FILE=%%I

echo Uploading %NEWEST_FILE%

(
    echo open ftp.example.com
    echo username
    echo password
    echo put C:sourcepath\%NEWEST_FILE% /target/path/%NEWEST_FILE%
    echo bye
) > ftp.txt

ftp.exe -s:ftp.txt

<小时>

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


For an easier and more reliable approach, use some more powerful 3rd party FTP client.

例如对于 WinSCP FTP 客户端,您可以使用 -latest 开关put 命令.

For example with WinSCP FTP client, you can use the -latest switch of its put command.

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

An example batch file (.bat):

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

您甚至可以让 WinSCP 为您生成脚本/批处理文件(您只需手动添加 -latest 开关).

You can even have WinSCP generate the script/batch file for you (you just need to add the -latest switch manually).

请参阅 WinSCP 文章关于上传最新文件.

(我是 WinSCP 的作者)

这篇关于Windows 批处理文件 - 仅将最新文件上传到 FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆