FTP in command prompt

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.

Thanks in advance.

Mikhail
 
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
 
Hello, Matthias:
On Wed, 02 Feb 2005 18:52:15 +0100: you wrote...

MT> :: create and execute Ftp script for remote dir
MT> DEL /Q %FTS% >NUL 2>&1
MT> if Not defined Anon echo/%User%>>%Fts%
MT> if Not defined Anon echo/%Pass%>>%Fts%
??>>> %Fts% echo cd %Rdir%
??>>> %Fts% echo dir %File%
??>>> %Fts% echo get %File%
??>>> %Fts% echo bye

Not to be totally obnoxious about this but we musn't forget security when
using sensitive data like passwords:
cacls %Fts% /G %USERNAME%:F
Which blocks access to others but the current user.

Regards, Paul R. Sadowski [MVP].
 
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.

Using the CLI 4NT:
IF %@FILESIZE["FTP:fu.bar"] EQ %@FILESIZE[fu.bar] ECHO Same size.

4NT provides transparent support for FTP (and to some extent for HTTP).
See: <http://jpsoft.com/help/ftpservers.htm>. Other command line
interpreters will probably require more elaborate solutions.
 
Back
Top