Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to check existence file on sftp

Status
Not open for further replies.

vuakhobo

Technical User
Apr 22, 2004
41
US
Hello,

Is there a way to check existence file on sftp?

Thanks in advance.
 
Something like:

Code:
if echo "ls filename" | sftp hostname 2>&1 | grep "No such file"
then
    echo "filename does not exist on hostname"
    exit 1
else
    echo "filename does exist on hostname"
fi

Annihilannic.
 
Something like this if you're running Korn shell on both sides...
Code:
if [[ "YES" == $(ssh user@hostname "[[ -f filename ]] && print YES") ]]
then
    print "filename exists on hostname"
else
    print "filename DOES NOT exist on hostname"
    exit 1
fi

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top