我在Windows XP上使用以下FTP脚本从Ubuntu云服务器下载zip文件。 每天在ubutnu服务器上创build一个zip文件,我将通过这个ftp脚本将它下载到windows。 我每天手动运行这个脚本,因为我必须编辑脚本的最后一行(mget /usr/backup_02-11-2010.Zip)以匹配今天的date。 我想编辑这个脚本,以便在预定的时间只下载今天的zip文件,而不需要每天编辑它。 很明显,date被附加到zip文件,格式为dd-mm-yyyy。 需要帮忙…
open server-ip-here username-here user-password-here lcd C:\Backup\files bin hash prompt mget /usr/backup_02-11-2010.zip
将包含所需date格式的variables添加到脚本中:
set mydate=%date:~0,2%-%date:~3,2%-%date:~6,4%
这将以格式dd-mm-yyyy回显当前date。 然后你可以使用variablesmydate来获取实际的文件:
get /usr/backup_%mydate%.Zip
在这里,它的工作,我从专家'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
脚本中的“或>>之前不应该有空格,在我的情况下脚本失败了,因为我在它们之前有空格,我正在尝试这么久。
该脚本创build一个名为one.txt的文件,第一行...> one.txt覆盖one.txt文件,其余文件附加到one.txt。