Command to check remote system

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

Guest

I need to execute few file transfer commands from a local system only after
the remote destination is reachable. Example:

Check whether I can reach 192.168.32.x
Then execute file transfer commands.

I tried ping the remote site and capture the %errorlevel%. But this is "0"
for success or failure.
 
Galop said:
I need to execute few file transfer commands from a local system
only after the remote destination is reachable. Example:

Check whether I can reach 192.168.32.x
Then execute file transfer commands.

I tried ping the remote site and capture the %errorlevel%. But this
is "0" for success or failure.
Hi

This is a "bug" in Win2k's ping.exe that is fixed in WinXP.

The best solution I have found to detect if a computer is online or not
is to search for the text "TTL=" in the output from ping.exe. I have
found it to work all situations/languages I have come up with.

So this should work fine for both WinXP and Win2k:

'--------------------8<----------------------
set host=128.33.12.144
set connected=N
for /f "Tokens=*" %%c in ('ping -n 1 %host% ^| FIND "TTL="') do (
set connected=Y
)
if "%connected%" EQU "Y" echo %host% is online
'--------------------8<----------------------
 
I need to execute few file transfer commands from a local system only
after the remote destination is reachable. Example:

Check whether I can reach 192.168.32.x
Then execute file transfer commands.

I tried ping the remote site and capture the %errorlevel%. But this is
"0" for success or failure.

Instead of PING, you could try the freeware ALIVE (which does return an
errorlevel) available at:

http://wettberg.home.texas.net/freeware.htm

But, just PINGing may tell you that the computer is on, but not whether it
actually is ready to accept file transfers. If a computer boots up, it may
answer a PING before the server and logon services are fully running. You
may have to insert a delay if this is a possiblity.

You could also try something like:

IF EXIST \\192.168.32.x\sharename (insert file transfer command here)
 
Thankyou very much to both of you. Actually, I need to perform file transfer
using batch mode ftp with batch script. I agree that, ping may go though but
ftp may not go though if the ftp service is not started at other end. Is
there a better way to manipulate this issue?
 
Torgeir said:
Hi

This is a "bug" in Win2k's ping.exe that is fixed in WinXP.

The best solution I have found to detect if a computer is online or
not is to search for the text "TTL=" in the output from ping.exe. I
have found it to work all situations/languages I have come up with.

So this should work fine for both WinXP and Win2k:

'--------------------8<----------------------
set host=128.33.12.144
set connected=N
for /f "Tokens=*" %%c in ('ping -n 1 %host% ^| FIND "TTL="') do (
set connected=Y
)
if "%connected%" EQU "Y" echo %host% is online
'--------------------8<----------------------

The following adaptation is backwardly compatible


@echo off
if #%1==# goto usage
if not #%2==# goto usage
set ol=off
ping -n 1 %1 |FIND "TTL=">nul
if not errorlevel 1 set ol=on
if "%connected%" == "Y" echo %1 is %ol%line
goto exit
:Usage
echo Usage is %0 hostname or IP
:exit
 
Torgeir Bakken (MVP) said:
Hi

This is a "bug" in Win2k's ping.exe that is fixed in WinXP.

Interesting. I just pinged (pung?) a non-existent IP address, got four
"Request timed out" responses, and the errorlevel was set to 1. Pinging
localhost returned, as expected, a code of 0. But what do these errorlevel
codes tell you? I would guess that 0 means that some response was received
and that 1 means none. Unless this assumption can be verified, I would
consider looking for "TTL=" as being the more reliable method.

/Al
 
Al said:
Interesting. I just pinged (pung?) a non-existent IP address, got four
"Request timed out" responses, and the errorlevel was set to 1. Pinging
localhost returned, as expected, a code of 0. But what do these errorlevel
codes tell you? I would guess that 0 means that some response was received
and that 1 means none. Unless this assumption can be verified, I would
consider looking for "TTL=" as being the more reliable method.
Hi

Yes, pinging a non-existing computer name/ip address will give error
level 1 on Win2k, but if you ping a computer that is registered in your
DNS, but the computer is offline, Win2k will return error level 0,
while WinXP will return error level 1 (that is more correct, as
ping.exe was not able to connect to the computer).
 
Thankyou very much to both of you. Actually, I need to perform file transfer
using batch mode ftp with batch script. I agree that, ping may go though but
ftp may not go though if the ftp service is not started at other end. Is
there a better way to manipulate this issue?

This is how I do that kind of thing using 4NT, a commercial CLI:
IFTP "ftp://192.168.32.x"
IFF %_? EQ 0 THEN
COPY sourcefile "ftp:"
IFTP /C
ELSE
ECHO IFTP failed.
ENDIFF

IFTP is a built-in command in 4NT; it provides for transparent file
operations to FTP hosts; it's documentetd at
<http://jpsoft.com/help/iftp.htm>.
 
Back
Top