PDA

View Full Version : [ubuntu] copying contents through ssh



de1337ed
June 30th, 2011, 07:43 PM
I want to copy the contents of a directory through ssh. The problem I'm having is that I can use the cp -r terminal function, but that would cause the directory itself to also be copied. I just simply want whats inside to be copied to another directory. Because of the way I have my server laid out, I would have to copy the entire directory, then copy each element one by one inside that directory into the specified folder. This is really tedious. So, is there a way I can just copy its contents? I was thinking of zipping it, the unzipping it, but when you extract, it once again just creates a new directory, not the contents inside. Help please!

If this is confusing, this is what I'm trying to do:
Directory: ../random/
Currently after scp -r:
/home/blah/blah/random/(elements inside random)
what I want:
/home/blah/blah/(elements inside random)

i.r.id10t
June 30th, 2011, 08:09 PM
scp -r username@hostname:/path/to/random/* .

nmaster
June 30th, 2011, 08:11 PM
do you want to try using wildcards like '*'? its not clear what you are doing or what you want to do. could you just post the command you are trying to execute? then we can work together to modify that.

de1337ed
July 1st, 2011, 01:31 AM
do you want to try using wildcards like '*'? its not clear what you are doing or what you want to do. could you just post the command you are trying to execute? then we can work together to modify that.

Sorry if I'm unclear. But basically, i'm running the following command:

scp -r /path/to/directory/ username@server:/path/to/location

the issue is, that when i do this, i get the following at the server end:
/path/to/location/directory/. So like i get the entire directory copied. I just want the contents inside directory to be copied without them being wrapped in the directory.
So instead of /location/directory/"contents" i want /location/"contents". the issue is that scp -r takes the entire directory. The only other way i can think is if I copy each file inside the directory individually which can be very tedious.

de1337ed
July 1st, 2011, 05:43 AM
*bump* sorry, really need an answer.

e79
July 1st, 2011, 06:00 AM
cd /location/directory


scp * username@server:/path/to/location

Cheers

e79
July 1st, 2011, 06:29 PM
*bump* sorry, really need an answer.

So, did that helped ?

nmaster
July 1st, 2011, 06:31 PM
cd /location/directory
scp * username@server:/path/to/locationCheers

sorry for not responding earlier. e79 is right. without the 'cd':

scp /location/directory/* username@server:/path/to/location

for more info on using wildcards at the command line: http://www.robelle.com/smugbook/wildcard.html

e79
July 1st, 2011, 07:14 PM
I'm glad you could solve your issue !

Cheers

e79

de1337ed
July 7th, 2011, 01:52 AM
I'm glad you could solve your issue !

Cheers

e79

Sorry for responding so late, I went on vacation, so no laptop. Tried it right now and it worked. Thanks a lot everyone :popcorn: