Solved

How do I capture FTP errors from a DOS script ?

Posted on 2004-09-21
5
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 96

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Finding a job can be stressful - searches, resume tweaks, and networking events can be super boring. Luckily we're here to help you land your dream job!
If you want to move up through the ranks in your technology career, talent and hard work are the bare necessities. But they aren’t enough to make you stand out. Expanding your skills, actively promoting your accomplishments and using promotion st…
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…
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.

710 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