我在windows上使用下面的FTP脚本从ubuntu云服务器下载压缩文件。每天都会在ubutnu服务器上创建一个zip文件,我将通过这个ftp脚本将其下载到windows。我每天手动运行这个脚本,因为我必须编辑脚本的最后一行(mget/usr/back02-11-2010.Zip),以匹配今天的日期。我想编辑这个脚本,以便它将只在预定的时间下载今天的压缩文件,而不需要每天编辑它,当计划。很明显,日期是附加到压缩文件,并以dd格式。需要帮助..。
open server-ip-here
username-here
user-password-here
lcd C:\Backup\files
bin
hash
prompt
mget /usr/backup_02-11-2010.zip
发布于 2010-11-03 10:37:01
将包含所需日期格式的变量添加到脚本中:
set mydate=%date:~0,2%-%date:~3,2%-%date:~6,4%
这将以dd-mm-yyyy
格式回显当前日期。然后可以使用变量mydate
获取实际文件:
get /usr/backup_%mydate%.Zip
发布于 2011-01-26 05:25:24
在这里,它起了作用,我抄袭了专家“Weeheavy”,让它发挥作用:
@REM Beginning of one.bat
@Echo Off
@set mydate=%date:~-7,2%-%date:~-10,2%-%date:~-4%
@REM Next write the FTP commands into one.txt
@echo open server-ip-here> one.txt
@echo username-here>> one.txt
@echo password-here>> one.txt
@echo lcd G:\Backup\files>> one.txt
@echo bin>> one.txt
@echo hash>> one.txt
@echo prompt>> one.txt
@echo get /usr/backup_%mydate%.zip>> one.txt
@REM Finally run the FTP command with the one.txt file
ftp -s:one.txt
@REM End of one.bat
脚本中的>
或>>
之前不应该有任何空间,而在我的示例中,脚本失败了,因为我在它们前面有空格,而且我尝试了很长时间。
脚本创建一个名为one.txt的文件,第一行...> one.txt
覆盖one.txt文件,其余的附加到one.txt。
https://serverfault.com/questions/197646
复制相似问题