bash: check if remote file exists using scp bash: check if remote file exists using scp bash bash

bash: check if remote file exists using scp


using ssh + some shell code embedded in the cmd line; use this method when you need to take a decision before the file transfer will fail;

ssh remote-host 'sh -c "if [ -f ~/myfile ] ; then gzip -c ~/myfile ; fi" ' | gzip -dc > /tmp/pkparse.py

if you want to transfer directories you may want to "tar"-it first

if you want to use scp you can check the return code like this:

if scp remote-host:~/myfile ./ >&/dev/null ; then echo "transfer OK" ; else echo "transfer failed" ; fi

it really depends on when its important for you to know if the file is there or not; before the transfer starts (use ssh+sh) or after its finished.


well, since you can use scp you can try using ssh to list and see if the file is their or not before proceeding.