I need to use rsync
or scp
for copy file or file folder from remote server to computer.
To copy (synchronize) a file folder I use the following function:
foldertocomp() {
rsync -avz pi@192.168.1.5:"'/home/pi/Torrents/$1'"/* "/home/comp/Torrent/$1"
}
I can use the following functions to copy a file:
filetocomp() {
rsync -avz pi@192.168.1.5:"'/home/pi/Torrents/$1'" "/home/comp/Torrent/"
}
OR
filetocomp() {
scp pi@192.168.1.5:"'/home/pi/Torrents/$1'" /home/comp/Torrent
}
All these functions work well. But I need to combine these functions into one single function. Like this:
tocomp() {
Some code...
}
Use function:
tocomp "HERE name of folder OR name of file"
I think I need to build the function like this:
tocomp() {
if "$1 is a FILE"
rsync -avz pi@192.168.1.5:"'/home/pi/Torrents/$1'" "/home/comp/Torrent/"
elif "$1 is a FOLDER"
rsync -avz pi@192.168.1.5:"'/home/pi/Torrents/$1'"/* "/home/comp/Torrent/$1"
fi
}
But how to check $1
is a folder or file?
I found the following method: stackoverflow.com/a/4665080/10728472. But I think this method not for remote server.
How to check $1
is a folder or file on a remote server?