Solved

How do I capture FTP errors from a DOS script ?

Posted on 2004-09-21
5
373 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Phishing is at the top of most security top 10 efforts you should be pursuing in 2016 and beyond. If you don't have phishing incorporated into your Security Awareness Program yet, now is the time. Phishers, and the scams they use, are only going to …
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
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.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now