Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

Batch File

Feb 21, 2008 11:44AM PST

Hi everyone,

I do not write batch files nor do I program. I only design web site and maintain network servers. I need help with the following. Basically, I wrote this batch file and I need to make the batch file create an output.log that tells me whether the FTP process the files over successfully or failed to process (transfer). I need the date/time on the log also. This is what i have so far.

ftp -s:ftpscript.txt 192.168.0.2
del *.csv
@echo off
exit

Thanks in advance!

Discussion is locked

- Collapse -
So why not...
Feb 21, 2008 11:48AM PST

Add a > or 2> to the ftp line with the file to catch the output?

- Collapse -
You mean like this...?
Feb 21, 2008 12:15PM PST

Is this what you meant?

ftp -s:ftpscript.txt 192.168.0.2 >> output.log
del *.csv
@echo off
exit

- Collapse -
Re: batchfile
Feb 21, 2008 5:31PM PST

Generally, @echo off is the first command to suppress output on the screen, not the last command. And you might want to delete output.log to start with to have a fresh copy (use single > then) in stead of appending to an existing one.

Then maybe add a small program or script to analyze the logfile. If it ends on something like:
221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
221 Logout.
everything went fine. If it didn't there was an error.

Kees

- Collapse -
Alternative.
Feb 21, 2008 5:48PM PST
- Collapse -
Thank you ALL
Feb 22, 2008 12:20AM PST

for your help! Appreciate your time in teaching me here. Thanks again!

- Collapse -
I found out ...
Feb 22, 2008 4:51AM PST

the errorlevel method doesn't work. Simply by trying it, because I needed it also.
For a test I changed the password in the executed file, so there was an errormessage and no files were transferred. Still echo %errorlevel% displayed 0. But the last line minus one of the log said 0 files were transferred. So that's what you should check.

Sorry for the wrong information. The lesson to be learned: always check what you find on the net.

Kees

- Collapse -
Send Result to Email Address
Feb 27, 2008 11:10PM PST

OK, so I got the below to work but now I want to have the script to send me an email of the result so I don't have to log into the server all the time to check for the log.

What should I add and be using to get the result from the log to email to me?

@ECHO OFF

ftp -n -s:ftpscript.txt 127.0.0.1

date /T >>CC.log
if ERRORLEVEL 1 (echo Failed >>CC.log) else (echo Succeeded >>CC.log
del *.csv)

:EOF

- Collapse -
Re: batchfile
Feb 28, 2008 5:12AM PST

This won't work for two reasons.
1. The errorlevel is reset to 0 by the date command, so you that in front of the ftp-command, not after!
2. And, as I said below, it seems ftp will end with errorlevel 0 always, even if it doesn't succeed. Convince yourself: >ftp/open x/bye, then >echo %errorlevel%. That's 0.

Anyway, to send an email from a batch file use any batch email program found by http://www.google.com/search?q=send+email+from+batch
A simple and free program to do it is blat (discussed in http://www.msexchange.org/articles/Sending-Email-without-Client.html).

Hope this helps.


Kees

Kees