I have a script on a Linux box which scp the files to windows server without any issues. but there are time frames where the windows server will not be available due to maintenance. hence I need to check if the remote location is available before running the scp command.
You could try a simple ping host before running the scp , but there is always the chance that your Windows server will go down between the time that you run the ping and the time that you run the scp .
It is frequently easier to just check whether or not the scp command succeeds...
if scp "$sourcepath" "$destpath"
then echo "scp of $sourcepath to $destpath succeeded"
else # Add "scp $sourcepath $destpath" to a list of copy commands that
# need to be rerun later.
echo "scp \"$sourcepath\" \"$destpath\"" >> /path/to/todo_list
# Note that the diagnostic from scp will serve as your visual
# indication that the scp failed this time, but you can also add
# your own diagnostic here if you want to.
fi
Just a word of caution about nmap in that it can be badly used too easily and excessive or injudicious use may be seen as a hacking attempt by either the target host(s) or networks and automatic defences may be causing you to get blocked or may trigger blocking future connections if you are too aggressive in your probing.
Is it the very long timeout that you are worried about? I agree that you should try the option -o ConnectTimeout=5 where 5 is a configurable number of seconds to wait for the connection to open. Don't make it too short or you may always fail to connect.