Hi Pasha,
Wow.. Less than 30 days old. You're really staying on top of this TA.
Thanks again for all your hard work.
With regards to this question:
I recommend points to pbarrette (me).
pb
Main Topics
Browse All TopicsAll,
I am using the standard Microsoft FTP on Win2k to ftp files between servers. The two questions are, how do I catch an error in the ftp process i.e. the file didn't completely transfer and can I capture the speed at which the file is transfered? I am using the mput and mget commands.
Thanks
Chris
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: pbarrettePosted on 2003-11-25 at 14:08:49ID: 9820976
Hi johanzn,
------ ------
---- ----
----
----
Capturing FTP errors while using the command-line FTP client can be difficult. There are several different ways that errors can manifest themselves. The most difficult is when there is a connection interruption and the client hangs waiting for a command to complete. In this case, the FTP session must be manually killed and a batchfile cannot detect a failure since it will not continue past the hung FTP session.
On the other hand, if your sessions are exiting normally, but there were file transfer errors then you can just parse through the log file to look for those errors. Similarly, the transfer speeds can be parsed out of the log file as well.
Assuming that you have a simple ftp script:
:: -------MyFTPScript.txt----
open my.host.com
user username
password password
bin
prompt
dir
mget *.htm
mput *.gif
bye
:: -------MyFTPScript.txt----
And you are logging the output using a simple batchfile like this:
:: -------MyFTPBatch.bat-----
@ECHO OFF
FTP -s:MyFTPScript.txt > MyFTPLogfile.log
:: -------MyFTPBatch.bat-----
Then we can combine all of that into a single, 2 stage batchfile like this:
:: -------MyFTPBatch.bat-----
@ECHO OFF
:: -----------
:: Set up an FTP header
:: which can be reused
:: -----------
ECHO open my.host.com>FTPheader.txt
ECHO user username>>FTPheader.txt
ECHO password password>>FTPheader.txt
:: -----------
:: Create the script used
:: to transfer the files
:: -----------
TYPE FTPheader.txt > FTPScript.txt
ECHO bin >>FTPScript.txt
ECHO prompt >>FTPScript.txt
ECHO mget *.htm >>FTPScript.txt
ECHO mput *.gif >>FTPScript.txt
ECHO bye >>FTPScript.txt
:: -----------
:: Perform the file xfer and
:: log the results.
:: -----------
FTP -s:FTPScript.txt > FTPXferLog.txt
:: -----------
:: Create the script used
:: to get the remote file sizes.
:: -----------
TYPE FTPheader.txt > FTPScript.txt
ECHO dir >>FTPScript.txt
ECHO bye >>FTPScript.txt
:: -----------
:: Grab the DIR listing and
:: dump it to a separate log.
FTP -s:FTPScript.txt > FTPSizeLog.txt
:: -----------
:: Clean up the mess
:: -----------
DEL FTPheader.txt
DEL FTPScript.txt
:: --------
:: Find filesizes and filenames on FTP server.
:: There's a little extra here because FTP
:: returns unix formatted data, which must
:: be stripped before we can use it.
:: --------
FOR /F "TOKENS=5,9" %%F IN ('TYPE FTPDIR.DAT^|FIND "-r"^|FIND /V "dr"') DO (
SET FILE=#%%F %%G#
CALL :PROCREM
)
GOTO LOCAL
:PROCREM
ECHO %FILE%>>RFILES.DAT
GOTO END
:: --------
:: Find filesizes and filenames for local files.
:: --------
:LOCAL
FOR /F "TOKENS=3,4" %%F IN ('DIR /A-D /-C^|FIND "."') DO (
ECHO %%F %%G>>LFILES.DAT
)
:: --------
:: Compare to see what we have and
:: produce an error log for differences.
:: --------
FOR /F "TOKENS=1,2 DELIMS=# " %%F IN ('TYPE RFILES.DAT^|FINDSTR ".htm .gif"') DO (
TYPE LFILES.DAT |FINDSTR ".htm .gif" |FINDSTR /C:"%%F %%G" >NUL
IF ERRORLEVEL 1 ( ECHO Possible error on transfer of file: "%%G" >> Errors.log )
)
:: -------
:: Search the transfer log for FTP
:: errors (Code 5XX) and append to log.
:: -------
TYPE FTPXferLog.txt |FINDSTR /B "5[0-9][0-9]"
:: -------
:: Get the list of transfer speeds into
:: an xfer speed log.
:: -------
FOR /F "DELIMS=" %%F IN ('TYPE FTPXferLog.txt^|find "ytes/sec"') DO (
ECHO %%F >> XferSpeeds.log
)
:: -------MyFTPBatch.bat-----
This still doesn't give you the filename coupled with transfer speed, and the whole batchfile is rather large, but it should get the job done with minor tweaking for your files.
Hope this helps,
pb