Thursday, January 27, 2011

Zip and FTP a File via a batch script

I am trying to ZIP and FTP a file in one batch file. The Zip part works, but the FTP application reads the entire batch script, rather than just the lines below the FTP commands, causing errors

If these files are nor read sequentially, how do I Zip and FTP in the same batch file?

@echo off
:: zip the file(s)
7z a -tzip c:\test.zip c:\unst.log
:: ftp the files
C:\WINDOWS\system32\ftp.exe -s:%0
open 10.1.7.10
myusername
mypassword
binary
put c:\test.zip
quit
pause
::exit
  • I am not sure on how the %0 works but doing on the follow way it works just fine for me:

    @echo off
    C:\WINDOWS\system32\ftp.exe -s:ftp_data.txt
    pause
    

    Where ftp_data.txt has the follow content:

    open 10.0.0.2
    username
    password
    binary
    put the_file_i_want_to_upload.txt
    quit
    
    Adrien : the `%0` is telling ftp to use the currently executing .bat file as the input to FTP, which is what's causing the OP's errors.
    Prix : thanks, i am not much into batch coding hehe ...
    From Prix
  • Is there a requirement to keep them all in one file? Because what you're doing is telling it to parse itself for the commands to feed to FTP, which (clearly) won't work.

    Easiest (and normal) way to do this would be to have a separate file ftp_script.txt that has the FTP commands.

    From Adrien

0 comments:

Post a Comment