我遇到了一个批处理脚本的问题,该脚本应该压缩一些pdf文件并将它们上传到FTP服务器。
我的脚本如下所示:
@echo off
set d=%date:~0,2%%date:~3,2%%date:~6,4%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%
set file="C:\Program Files (x86)\7-Zip\7z.exe" a -r 46730_%d%_%t%.zip *.pdf
echo open my.host.name>> temp
echo myusername>> temp
echo mypassword>> temp
echo ascii>> temp
echo cd /
echo binary
echo put %file%>> temp
echo close>> temp
echo quit>> temp
ftp -s:temp
del temp
TIMEOUT /T 5
使用正确的名称创建zip文件,然后我可以打开它。我很确定问题在于脚本的上传部分,但我在谷歌找不到任何有用的解决方案:-(收件人无法打开zip文件。他收到此错误:可能'nt打开文件作为archieve。
我做错了什么?
答案 0 :(得分:0)
您缺少将“CD /”和“二进制”指令重定向到临时文件... 并且您正尝试在“file”变量中设置命令指令...
试试这个:
@echo off
set d=%date:~0,2%%date:~3,2%%date:~6,4%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%
Start /W "C:\Program Files (x86)\7-Zip\7z.exe" a -r "46730_%d%_%t%.zip" "*.pdf"
set "file=46730_%d%_%t%.zip"
(
echo open my.host.name
echo myusername
echo mypassword
REM Use a correct dir command, "cd /" isn't openning any folder
REM echo cd ".\folder\"
echo binary
echo put "%file%"
echo close
echo quit
)> "%TEMP%\ftp.txt"
ftp -s:"%TEMP%\ftp.txt"
TIMEOUT /T 5
如果遇到问题,最好使用WPUT命令:
C:\Users\Administrador\Desktop>wput --help
Usage: wput [options] [file]... [url]...
url ftp://[username[:password]@]hostname[:port][/[path/][file]]
Startup:
-V, --version Display the version of wput and exit.
-h, --help Print this help-screen
Logging and input file:
-o, --output-file=FILE log messages to FILE
-a, --append-output=FILE append log messages to FILE
-q, --quiet quiet (no output)
-v, --verbose be verbose
-d, --debug debug output
-nv, --less-verbose be less verbose
-i, --input-file=FILE read the URLs from FILE
-s, --sort sorts all input URLs by server-ip and path
--basename=PATH snip PATH off each file when appendig to an URL
-I, --input-pipe=COMMAND take the output of COMMAND as data-source
-R, --remove-source-files unlink files upon successful upload
Upload:
--bind-address=ADDR bind to ADDR (hostname or IP) on local host
-t, --tries=NUMBER set retry count to NUMBER (-1 means infinite)
-nc, --dont-continue do not resume partially-uploaded files
-u, --reupload do not skip already completed files
--skip-larger do not upload files if remote size is larger
--skip-existing do not upload files that exist remotely
-N, --timestamping don't re-upload files unless newer than remote
-T, --timeout=10th-SECONDS set various timeouts to 10th-SECONDS
-w, --wait=10th-SECONDS wait 10th-SECONDS between uploads. (default: 0)
--random-wait wait from 0...2*WAIT secs between uploads.
--waitretry=SECONDS wait SECONDS between retries of an upload
-l, --limit-rate=RATE limit upload rate to RATE
-nd, --no-directories do not create any directories
-Y, --proxy=http/socks/off set proxy type or turn off
--proxy-user=NAME set the proxy-username to NAME
--proxy-pass=PASS set the proxy-password to PASS
FTP-Options:
-p, --port-mode no-passive, turn on port mode ftp (def. pasv)
-A, --ascii force ASCII mode-transfer
-B, --binary force BINARY mode-transfer
--force-tls force the useage of TLS
See the wput(1) for more detailed descriptions of the options.
Mail bug reports and suggestions to <itooktheredpill@gmx.de>