0

I have some local files at:

/doc/dir-monkey/monkey.txt
/doc/dir-monkey/monkey.xml

/doc/dir-dog/dog.txt
/doc/dir-dog/dog.xml

/doc/dir-cat/cat.txt
/doc/dir-cat/cat.xml

Now I want to upload them to a remote server via scp

I want to keep the directory the same way and overwrite the old files if necessary. I know that I can only upload one file at a time and I found some tips about compress the files before and then decompress them remotely. Is there any detailed instructions for this?

I am currently using MacOSX 10.10 and the remote server is as follows:

Distributor ID: Debian
Description:    Debian GNU/Linux 7.5 (wheezy)
Release:    7.5
Codename:   wheezy
2
  • Can you only use scp, or can you also use sftp, rsync, or arbitrary commands over ssh? Commented May 9, 2015 at 16:06
  • @Gilles yes I can use anything. taking rsync for example, will it automatically optimize the upload like zip it before uploading then unzip? because I'm gonna probably upload a lot of small files. thanks Commented May 14, 2015 at 12:22

3 Answers 3

3

Always refer to the manual for your distribution as the available arguments & options vary. Use man scp.

As for a recursive copy in OSX using SCP the following should work:

scp -r /local/directory [email protected]:/remote/directory

1
  • 1
    +1 and i want to note that that command will create directory under directory at remote
    – Esref
    Commented May 9, 2015 at 8:08
1

As stated by jas, scp -r localDir user@server:remoteDir should do a recursive copy. If you worry about timestamps of your files, that add the -p flag and they are also kept as on you local server (else they will be changed to the time of copy).
This is fine with small volumes of data. If you have to regularly do this on large volumes (large number of files) and only do want to update what has changed, then I'd recommend using rsync.

It'd work like this :

rsync -avz locaDir user@remoteServer:remoteDir

You'd need rsync on your osx and ubuntu though (which is possible ;)).

1
  • sorry for the late reply. will the rsync automatically optimize the upload like zip it before uploading then unzip? because I'm gonna probably upload a lot of small files. thanks! Commented May 14, 2015 at 12:20
0

I can't tell if this is everything in the structure or just a component. If this is everything, you can do something like scp -r /doc remote:/doc_copy.

If this is only a subset, then it's more difficult to do it all in scp. Some options might be to scp them one at a time, or use something like rsync (and its more expressive include/exclude interface).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .