0

I am having problems with a batch script that should zip some pdf files and upload them to a FTP server.

My script looks like this:

@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

The zip files is created OK with the correct name, and I am able to open it afterwards. I'm pretty sure the problem(s) lies in the upload part of the script, but I can't find any working solution on google :-( The reciever is not able to open the zip file. He gets this error: Could'nt open the file as an archieve.

What am I doing wrong ??

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417

1 Answers1

0

You are missing to redirect the "CD /" and "Binary" instruction to the temp file... And you are trying to set a command instruction in the "file" variable...

try this:

@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

If you have problems you better can use the WPUT command:

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>
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • Hi again. Now it is working. I used your example to connect to the ftp and put the data in the ftp.txt file. Thanks alot for the help – user1856749 Nov 30 '12 at 09:28