0

我遇到了一个批处理脚本的问题,该脚本应该压缩一些 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将文件作为档案打开。

我究竟做错了什么 ??

4

1 回答 1

0

您缺少将“CD /”和“二进制”指令重定向到临时文件...并且您正在尝试在“文件”变量中设置命令指令...

尝试这个:

@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 命令:

https://sourceforge.net/projects/wput/files/wput/pre0.6/wput-pre0.6.zip/download?use_mirror=freefr&download=

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>
于 2012-11-28T10:09:31.637 回答