Solved

How do I capture FTP errors from a DOS script ?

Posted on 2004-09-21
5
376 Views
Last Modified: 2010-05-18

I have been asked to take an existing MSDOS script written for W2K and capture FTP error info.
Inside a DOS script, a second file is called with FTP info. If there are any errors, I want to capture them.

For example, inside the existing DOS script, it says something like:
ftp -n -s:PushPosPayAcct.FTP>C:\logfile.txt
Where it calls a file named PushPosPayAcct.FTP.

I found an article on how to get the ftp output info written to a log file:
http://www.experts-exchange.com/Miscellaneous/Q_20979274.html?query=FTP+error+logging&clearTAFilter=true
But this method gets all output from the FTP process.
Is there any way to capture a failure. Specifically, I am looking for errors such as 'path not found' or 'login failed'. One suggestion here was to possibly read the system FTP log.
Any info would be appreciated.
0
Comment
Question by:MGray55
5 Comments
 
LVL 15

Expert Comment

by:nicholassolutions
ID: 12115756
If you have perl installed you could have your DOS script save the whole output, and then parse the log files afterwards for errors.
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 400 total points
ID: 12117586
Not sure if this will work, but....

ftp -n -s:PushPosPayAcct.FTP 2> C:\errlogfile.txt 1> c:\logfile.txt

2 is standard error
1 is standard out

IF FTP is coded correctly and spits out to a console the error messages as standard error, then that should work.
0
 

Expert Comment

by:jditcham
ID: 12118323
I recommend you have a look at a tool called cURL http://curl.haxx.se , there's both dos and windows compiles for it...

It's one of the neatest little file transfer utilities I've found supporting FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE and LDAP.

It has massive exit code support for reporting errors 60+ last time I downloaded it..



0
 

Author Comment

by:MGray55
ID: 12122052
I should add that the DOS Script that I need to write will be on a server where nothing can be installed.
I cannot use anything but what is available on the machine already (Win2k - MS-DOS)
The Machine is WIndows2k and does not have Java installed.
0
 

Author Comment

by:MGray55
ID: 12135529
Thanks leew. That worked perfectly.

In case anyone is searching this topic in the future, here is what I ended up doing with this code.
I send the error logs to a file named error.log, and regular output to a file named %timestamp%.log
Since error.log is always created, whether there is an error or not, I created loop to see if there is any text in the file.
If I find text, I go to a sub-routrine named ALERTm that appends an .eml header file, to the error.log with the regular out put
and moves it to my windows C:\inetpub\mailroot\pickup directory to send the alert email.

Here is a partial example of the code:

@rem   *********************************************************
@rem   *  Create a start-time stamp variable:
@rem   *  Use for logging.
@rem   *********************************************************
       :: timestamp
       for /f "tokens=2,3,4 delims=.-/ " %%i in ('date/t') do set timestamp=%%k.%%i.%%j
       FOR /F "TOKENS=5-8 DELIMS=:. " %%F IN ('ECHO.^|TIME') DO (
       SET HR=%%F
       SET MN=%%G
       SET SC=%%H
       SET MS=%%I
       )
       set fulltimestamp=%timestamp%_%HR%.%MN%.%SC%
       :: timestamp ends

@rem   *********************************************************
@rem   *  Declare all the file paths as variables
@rem   *********************************************************
       set ROOT_DIR=\WebCM\cmd
       set LOG_NAME=ftpPosPayEx_%timestamp%.log
       set ERR_LOG_NAME=ftpPosPayEx_ERROR.log
       set LOG_PATH=%ROOT_DIR%\%LOG_NAME%
       set ERR_LOG_PATH=%ROOT_DIR%\%ERR_LOG_NAME%
       set ALERT_NAME=alert
       set ALERT_MAIL=alert.txt
       set EMAIL_PATH=C:\inetpub\mailroot\pickup
       set ARCH_PATH=%ROOT_DIR%\logs
       set FILE_NAME=P_PNHPosPay.txt
       set FTP_FILE=d:\webcm\cmd\PushPosPayAcct.FTP

@REM ***********************************************************************************
@REM **   Attempt FTP push here
@REM **   Also check for entries in error log. If log is not
@REM **       empty, send an email alert
@REM ***********************************************************************************
     ftp -n -s:%FTP_FILE% 2>%ERR_LOG_PATH% 1>%LOG_PATH%

     FOR /f %%a IN (%ERR_LOG_NAME%) DO (

        set Input=%%a
        set /a Length+=1
        set Input=%Input:~1%
        rem echo %%a
     )

 :DONE

      @REM **  If %Length% is greater or equal to one, than there is info in the error log
      @REM **    send an email alert
      if /i %Length% GEQ 1 goto :ALERT


:ALERT
     @ECHO FTP Process has encountered a problem >>%ALERT_NAME%
     @ECHO during the xxx execution. >>%ALERT_NAME%
     @ECHO Please investigate. >>%ALERT_NAME%
     @ECHO %FILE_NAME% may not have been pushed >>%ALERT_NAME%
     @REM @ECHO See %LOG_PATH% For More Information  >>%ALERT_NAME%
     @ECHO Message From FTP Service is as follows: >>%ALERT_NAME%
     @ECHO *************************************** >>%ALERT_NAME%
     COPY %ALERT_NAME%+%ERR_LOG_PATH% %ALERT_MAIL%
     @REM ***********************************************************************************
     @REM **   Send alert email if it exists
     @REM ***********************************************************************************
          IF EXIST %ALERT_MAIL% COPY ppextract.eml+%ALERT_MAIL%+%LOG_PATH% %EMAIL_PATH%
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Energy conservation - Edward Leedskalnin 20 103
Communication with an active RFID 7 67
new year deals on hware.. 4 42
Problem to file 13 41
I really like Experts Exchange but the text formatting tags are pretty basic. For example in an article I wrote I found that when I put a "[bullet]" tag in front of a list of items and a closing "[/bullet]" tag at the end I expected that each item i…
Stuck in voice control mode on your Amazon Firestick?  Here is how to turn it off!!!
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question