在x天以上的FTP上批量删除文件 [英] Batch delete files on FTP older than x days
问题描述
发现了几个针对本地的解决方案,但需要一个用于FTP动作的解决方案:
我有一个每日批处理脚本来备份本地MySQL数据库,但是我也将它们ftp到备份服务器。
在本地,我使用 forfiles
删除超过14天的文件:
forfiles -pC:\whatever-s -m *。* -d 14 -ccmd / c del @path
我也想在FTP上做同样的事情,一旦最新的备份文件被转储到FTP服务器上运行在Windows Server 2008 R2上。
如何扩展我的批处理文件以执行此操作?
cd \ [保存文件所在目录的路径]
echo off
echo user [ftp username]> ftpup.dat
echo [ftp password]> ;> ftpup.dat
echo binary>> ftpup.dat
echo put [FullBackup。%backupdate%.zip]>> ftpup.dat
echo quit>> ftpup .dat
ftp -n -s:ftpup.dat [myserver.com]
del ftpup.dat
使用内置的 ftp.exe
实现起来很麻烦,因为非常好回答@PA。显示。
您最好使用一些功能更强大的脚本第三方FTP客户端。
例如 WinSCP FTP客户端,与以下内容一样简单:
winscp.com / ini = nul / log = delete.log / command ^
open ftp:// username:password@ftp.example.com/^
rm / remote / path / *< 14D^
exit
请参阅具有时间限制的文件掩码。
$ b
(我是WinSCP的作者)
Found several solutions for local, but need one for FTP action:
I have a daily batch script to backup MySQL databases locally, however I also ftp them to a backup server.
Locally, I am using forfiles
to delete files older than 14 days:
forfiles -p "C:\whatever" -s -m *.* -d 14 -c "cmd /c del @path"`
The same I would like to do on FTP, once the newest backup files are dumped into FTP server running on Windows Server 2008 R2.
How do I extend my batch file to do this action?
cd\[path to directory where files are saved]
echo off
echo user [ftp username]>ftpup.dat
echo [ftp password]>>ftpup.dat
echo binary>>ftpup.dat
echo put [FullBackup.%backupdate%.zip]>>ftpup.dat
echo quit>>ftpup.dat
ftp -n -s:ftpup.dat [myserver.com]
del ftpup.dat
It's cumbersome to implement with the built-in ftp.exe
, as the very good answer by @PA. shows.
You better use some more powerful scriptable 3rd party FTP client.
For example with WinSCP FTP client, it's as trivial as:
winscp.com /ini=nul /log=delete.log /command ^
"open ftp://username:password@ftp.example.com/" ^
"rm /remote/path/*<14D" ^
"exit"
See file masks with time constraints.
(I'm the author of WinSCP)
这篇关于在x天以上的FTP上批量删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!