Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
I'm a bit confused. Is there a requirement to keep them all in one file? Easiest way to do this would be to have a separate file ftp_script.txt that has the FTP commands. –  Adrien Aug 6 '10 at 17:18
    
your ftp.exe command tries to use the upload commands %0. However, %0 in a batchfile means the batchfile itself (or more precise: that path+name under which the batchfile was called). This can not work, since your example batchfile has some non-ftp commands at the beginning (like the @echo, :: and the 7z commands)... –  Kurt Pfeifle Aug 8 '10 at 1:45
add comment

3 Answers

up vote 2 down vote accepted

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
share|improve this answer
    
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. –  Adrien Aug 6 '10 at 17:38
    
thanks, i am not much into batch coding hehe ... –  Prix Aug 6 '10 at 18:21
add comment

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.

share|improve this answer
add comment

First of all, Is ur script doing what u want to do in all the cases? exceptions?

I see that it will overwrite the destination file if it exists... too bad if they are important files

If the transmision fails... No log!! (Important for production enviroments if u have to search thought the months of logs)

Although at first glance it may be interesting to use the FTP client from Microsoft, if you think that the project will last more than a week, I think you should consider using more powerful FTP/SFTP clients.

Clients who are able to get logs, that are able to avoid overwriting files if they exist (and so you wish), that can be integrated with other scripts (PowerShell or Wscript for example) ...

There're quite a bunch out of them, but one with quite use is WinScp. It will improve ur work now, and in the future, cos it's a really nice app.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.