Mikhail said:
Let's say I have a 500 mb file transferred at client ftp, what I usually do
is manually check the bytesize of the file at remote site if it is the same
with the local bytesize. I want to do this automatically can anyone please
help me to achieve this.
That is possible, but IMO not sufficient to assure a correct trans-
mission. An md5 key would be better.
To get get the remote files size you will need to parse the dir output
which depends on the make and version of your ftp server.
This is a sample output from *my* ftp server.
- [RWCEAFMS] admin 8 Dec 05 2004 dummy.txt
If you log actions on the remote side you can parse for the 4th arg
in this example. The local size can be retrieved with a for and the
tilde z option.
This is a sample batch which I tested ok here with the above layout.
All variable data is in set commands to ease adaption.
If you use anonymous mode uncomment the line set Anon=-A , user and
pass could be left blank then.
::FTP-Check-siz.cmd::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
set Fts=%~n0.Fts
set Log=%~n0.flg
set Host=ftp.yourhost.com
::set "Anon=-A "
set User=youruser
set Pass=yourpass
set Rdir=/remotedir
set File=dummy.txt
set "RFS="
:: create and execute Ftp script for remote dir
DEL /Q %FTS% >NUL 2>&1
if Not defined Anon echo/%User%>>%Fts%
if Not defined Anon echo/%Pass%>>%Fts%FTP -v -s:%Fts% %Anon% %Host% >%Log% 2>Nul
:: extract remote file size for %file% from Log. has to be tweaking
for /f "tokens=4" %%A in ('findstr /I "%File%" ^<%Log%') do set RFS=%%A
if NOT defined RFS Echo Error checking RFS remote file size&exit /b 1
for /f %%A in ('DIR /B %FILE%') do set LFS=%%~zA
if NOT defined LFS Echo Error checking LFS local file size&exit /b 1
echo.Remote file size : %RFS%
echo.Local : %LFS%
if "%RFS%" NEQ "%LFS%" echo Error sizes don't match&exit /b 1
:: do cleanup
Del /Q "%~n0.f*" >Nul 2>&1
::FTP-Check-siz.cmd::::::::::::::::::::::::::::::::::::::::::::::::::
HTH