我正在制作一个bat文件压缩文件,然后通过ftp发送,一切正常但发送到ftp后的文件有时会被破坏,特别是当它的大和加密时,本地zip文件没问题。我在互联网上查了一下它说传输模式可能有问题,但是我把它设置为二进制和同样的问题。
@echo off
REM time format hhssmm
set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
REM echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
REM echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
REM echo secs=%secs%
REM date format yyyymmdd
set year=%date:~0,4%
REM echo year=%year%
set month=%date:~5,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
REM echo month=%month%
set day=%date:~8,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
REM echo day=%day%
set pass="password"
Start 7za.exe a file_%year%%month%%day%_%hour%%min%%secs%.zip * -r -mx9 -p%pass% -mhe
set "file=file_%year%%month%%day%_%hour%%min%%secs%.zip"
REM set username = all
REM set userpass = 12345
echo debug> ftpcmd.dat
echo user all> ftpcmd.dat
echo 12345>> ftpcmd.dat
echo binary>> ftpcmd.dat
status
echo put %file%>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat xx.xxx.xxx.xx
del ftpcmd.dat
pause
我正在使用7-Zip命令行可执行文件,7za.exe。压缩文件。 这是结果:
status
Connected to xx.xxx.xxx.xx.
220-FileZilla Server version 0.9.43 beta
220-written by Tim Kosse (tim.kosse@filezilla-project.org)
220 Please visit http://sourceforge.net/projects/filezilla/
ftp> debug
Debugging On .
ftp> user all
---> USER all
331 Password required for all
---> PASS 12345
230 Logged on
ftp> binary
---> TYPE I
200 Type set to I
ftp> put file_20140205_093700.zip
---> PORT xx,xxx,xxx,xx,xx,x
200 Port command successful
---> STOR file_20140205_093700.zip
150 Opening data channel for file upload to server of "/file_20140205_093700.zip"
226 Successfully transferred "/file_20140205_093700.zip"
ftp: 179312 bytes sent in 0,00Seconds 179312000,00Kbytes/sec.
ftp> quit
---> QUIT
221 Goodbye
Press any key to continue . . .
答案 0 :(得分:0)
感谢您的回答。我发现了这个问题。当文件发送到ftp时,7za.exe
仍在压缩,只需在启动exe后添加START / WAIT:
START /WAIT 7za.exe a file_%year%%month%%day%_%hour%%min%%secs%.zip * -r -mx9 -p%pass% -mhe
以下是更改后的漏洞脚本并进行了一些改进。它使zip文件密码受到保护,并通过ftp发送。 Yo可以在命令窗口中设置参数或将其保存在脚本中。
您只需要在同一个文件夹中使用7zip命令行(7za.exe)
@ECHO off
REM time format hhssmm
SET hour=%time:~0,2%
IF "%hour:~0,1%" == " " SET hour=0%hour:~1,1%
REM ECHO hour=%hour%
SET min=%time:~3,2%
IF "%min:~0,1%" == " " SET min=0%min:~1,1%
REM ECHO min=%min%
SET secs=%time:~6,2%
IF "%secs:~0,1%" == " " SET secs=0%secs:~1,1%
REM ECHO secs=%secs%
REM date format yyyymmdd (Adjust to local date format)
SET year=%date:~0,4%
REM ECHO year=%year%
SET month=%date:~5,2%
IF "%month:~0,1%" == " " SET month=0%month:~1,1%
REM ECHO month=%month%
SET day=%date:~8,2%
IF "%day:~0,1%" == " " SET day=0%day:~1,1%
REM ECHO day=%day%
REM set filename with current timestamp
SET filename=file_%year%%month%%day%_%hour%%min%%secs%.zip
REM to ask to set zip password
SET /p zippass=Set zip password:
REM to set the zip password instead of asking for it
REM SET zippass="p"
REM to ask for parameters
SET /p ftphost=Enter ftphost:
SET /p username=Enter user:
SET /p userpass=Enter password:
REM to save the parameters instead of asking for them
REM SET ftphost=xx.xxx.xxx.xx
REM SET username=all
REM SET userpass=12345
SET encrypt_headers=
REM SET encrypt_headers=-mhe
START /wait 7za.exe a %filename% * -r -mx9 -p%zippass% %encrypt_headers% -x!7za.exe -x!zip_ftp.bat -x!zip_ftp_ask.bat
SET file=%filename%
@ECHO off
ECHO user %username%> ftpcmd.dat
ECHO %userpass%>> ftpcmd.dat
ECHO bin>> ftpcmd.dat
ECHO put %file%>> ftpcmd.dat
ECHO quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat %ftphost%
DEL ftpcmd.dat
PAUSE