I am wondering if scp will create the target folder if it does not exist on the remote server. For example, would this work?
scp -r /data/install/somefolder [email protected]:/data/install/somefolder
Here the folder /data/install/somefolder
doesn't exist on ftp server, so would this command create it?
N.B. I have read about rsync but am not really sure how it works or how to use it yet.
With the scp command, you can specify the source (the file or directory to be copied) and the target (the location in which to copy the file or directory).
By default, existing files are overwritten. To control overwrite behavior, use --overwrite. (If the files are identical no transfer occurs regardless of this setting value.) Because scp uses authentication and encryption provided by ssh, a Secure Shell server must be running on the remote computer.
Copy or Download a File From Remote to Local Using SCP Just invoke SCP followed by the remote username, @, the IP address or host, colon, and the path to the file. If not specified, the default path is the remote user's home directory.
The Unix command scp (which stands for "secure copy protocol") is a simple tool for uploading or downloading files (or directories) to/from a remote machine.
To achieve the task with ssh and scp (instead of rsync):
Lets break into 2 steps :
ssh [email protected] "mkdir -p /data/install/somefolder"
scp -r /data/install/somefolder [email protected]:/data/install/somefolder
server="[email protected]" destiny="/data/install/somefolder" src="/data/install/somefolder" ssh "$server" "mkdir -p $destiny" && scp -r "$src" "$server:$destiny"
Short answer: no.
...but rsync does, which is why I have aliased scp
to rsync -Pravdtze ssh
on my box. Yes, that's a lot of switches, which in combination produces my preferred rsync behavior. As rsync does provide a very extensive set of switches and options, I suggest you do some research on it to see what fits your needs best. Man-page is a good place to start, but there are a lot of info easily available. Here's a decent list of examples.
Edit: Actually, in that particular case you posted, the folder will be created, as that's the folder you're copying. However, if you're trying to copy it to user@remotehost:somenonexistentfolder/somefolder
, then it will fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With