user1801932
user1801932

Reputation: 379

SCP is creating subdirectory... but I just want it to copy directly

I'm trying to use scp to copy recursively from a local directory to a remote directory.... I have created the folders on the remote side:

Remote Location (already created):

/usr/local/www/foosite

I am running scp from the local machine in directory:

/usr/local/web/www/foosite

But it's copying the "foosite" directory as a subdirectory... I just want the contents of the folder, not the folder itself...

Here is the command I'm using:

scp -r /usr/local/web/www/foosite [email protected]:/usr/local/www/foosite

Upvotes: 9

Views: 5465

Answers (2)

nortoon
nortoon

Reputation: 566

Old question, but I think there is a better answer. The trick is to leave the foosite directory off of the destination:

scp -r /usr/local/web/www/foosite [email protected]:/usr/local/www

This will create the foosite directory on the destination if it does not exist, but will just copy files into foosite if the directory already exists. Basically the -r option will copy the last directory in the path and anything under it. If that last directory already exists on the destination, it just doesn't do the mkdir.

Upvotes: 1

user1801932
user1801932

Reputation: 379

The problem is that if you don't use the asterisk (*) in the local part of the call, scp will create a new top level directory in the remote server. It should look like this:

scp -r /usr/local/web/www/foosite/* [email protected]:/usr/local/www/foosite

This says "Copy the CONTENTS" (but not the directory itself) to the remote location.

Hope this helps... Took me an hour or so to figure this out!!!

Upvotes: 9

Related Questions