I\'d like to write bash script to recursively list all files (with fullpaths) on sftp and interact with paths locally afterwards (so only thing for what sftp is needed is ge
This recursive script does the job:
#!/bin/bash
#
URL=user@XXX.XXX.XXX.XXX
TMPFILE=/tmp/ls.sftp
echo 'ls -1l' > $TMPFILE
function handle_dir {
echo "====== $1 ========="
local dir=$1
sftp -b $TMPFILE "$URL:$dir" | tail -n +2 | while read info; do
echo "$info"
if egrep -q '^d' <<< $info; then
info=$(echo $info)
subdir=$(cut -d ' ' -f9- <<< $info)
handle_dir "$dir/$subdir"
fi
done
}
handle_dir "."
fill URL with the sftp server data.
I scan the whole Internet and find a great tool sshfs
. Mount the remote directory tree through SSHFS. SSHFS is a remote filesystem that uses the SFTP protocol to access remote files.
Once you've mounted the filesystem, you can use all the usual commands without having to care that the files are actually remote.
sshfs
helps me a lot, may give you help, too.
mkdir localdir
sshfs user@host:/dir localdir
cd localdir
find . -name '*'