Check for existence of file on remote machine - sftp
883189Dec 7 2011 — edited Dec 10 2011HI
I need to connect to the remote machine x and get files from them to my local machine. For that I need to write a ksh script. Before getting the files from server x, I need to check if the file is present or not. If present, get the files. If files not present, get the error message. I tried a lot. But couldn't get any please help. The server x supports only SFTP I guess.
My test code is as follows:
#!/bin/ksh
value=$(find . -name test.txt)
if [ "$value" = "" ]
then print "No such file found"
else {
print " File found "
sftp user@x_servername
get test.txt
EOF
}
fi
But, this code is not working. Its asking for password and hunging up immediately. Is there any other method? Please do help. Its very urgent....