Use winrar and ftp commands to automatically backup files and automatically upload them to the specified ftp server

1. Use winrar to create a compressed package

First, collect the file path to be backed up into a text file. For example, the content of my rat.txt is as follows:

"C:\Documents and Settings\EvanZhang\Desktop\untitled.JPG"
"C:\Documents and Settings\EvanZhang\Desktop\Stationery Receipt Confirmation Form.xls"
"C:\Documents and Settings\EvanZhang\Desktop\test .exe"

Create a backup.bat file with the following contents

"C:\Program Files\WinRAR\WinRAR.exe" a -m5 -k -t -ag[YYYY-MM-DD-HH-MM-SS] c:\backup-.rar @c:\rar.txt
- a add files to the archive
-m5 set compression ratio
-k lock archives do not allow editing
-t test after compression -ag
generate file name with current date
c:\backup-rar generate archive prefix
@c:\rar.txt file to compress

2. Establish ftp command batch processing

Add the following line to backup.bat
ftp -s:c:\ftp.txt
to create, the content of ftp.txt is as follows
open ***.***.***.***
user
password
bin
put back*.rar
bye

open 主机名称   如open 
user   ftp用户名
password ftp帐户密码
bin 以2进制为传送
put back*.rar 是将刚才用rar 压缩的文件上传
bye 为结束ftp对话
3.将backup.bat 在windows 工作计划中指定运行时间
4.测试
backup.bat 完整内容如下:
"C:\Program Files\WinRAR\WinRAR.exe" a -m5 -k -t -ag[YYYY-MM-DD-HH-MM-SS] c:\backup.rar @c:\rar.txt
ftp -s:c:\ftp.txt

rar.txt完整内容如下:

"C:\Documents and Settings\EvanZhang\Desktop\untitled.JPG"
"C:\Documents and Settings\EvanZhang\Desktop\文具用品领用确认表.xls"
"C:\Documents and Settings\EvanZhang\Desktop\test.exe"

完整内容如下:

open ***.***.***.***
user
password
bin
put back*.rar
bye


运行测试,测试结果如下:

ftp> Connected to **.**.**.**
open **.**.**.**
220 Serv-U FTP Server v6.3 for WinSock ready...
User (**.**.**.**(none)): 
331 User name okay, need password.

230 User logged in, proceed.
ftp> bin
200 Type set to I.
ftp> put back*.rar
200 PORT Command successful.
150 Opening BINARY mode data connection for backup[2006-09-14-13-30-06].rar.
226 Transfer complete.
ftp: 747412 bytes sent in 11.94Seconds 62.61Kbytes/sec.

ftp> bye
221 Goodbye!

因winrar压缩实在图形界面下压缩的 所以看不到压缩记录,如果是在linux下面使用tar方式压缩的时候,压缩记录都会看的很清楚。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326393557&siteId=291194637