Does scp create the target folder if it does not exist [closed]
To achieve the task with ssh and scp (instead of rsync):
Solution
Lets break into 2 steps :
1. Create directory if missing:
ssh user@ftpserver.com "mkdir -p /data/install/somefolder"
2. Copy to it:
scp -r /data/install/somefolder user@ftpserver.com:/data/install/somefolder
Put them together
server="user@ftpserver.com"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.