3

I'm trying to copy a folder from my local computer to a remote server, but it only seems to be catching half of the files within the folder. Here's my scp command:

scp read_tree [email protected]:~/Work/gmovie

and this is the output I get:

.DS_Store                                                    100% 6148     6.0KB/s   00:00    
read_tree/check_syscalls.c: No such file or directory
read_tree/check_syscalls.h: No such file or directory
example.c                                                    100%  204     0.2KB/s   00:00    
Makefile                                                     100%  438     0.4KB/s   00:00    
read_tree.c                                                  100% 9350     9.1KB/s   00:00    
read_tree.h                                                  100% 1176     1.2KB/s   00:00    
read_tree/stringparse.c: No such file or directory
read_tree/stringparse.h: No such file or directory
read_tree/strtonum.c: No such file or directory
zacc.c                                                       100%  885     0.9KB/s   00:00    

I also tried using scp directly for one file, and got the same result. Any ideas on where I'm going wrong?

**I'm working in terminal on my mac

**EDIT: ls -al for the read_tree directory:

total 112
drwxr-xr-x@  13 name  staff   442 Jul 11 10:42 .
drwx------+ 109 name  staff  3706 Jul 11 10:42 ..
-rw-r--r--@   1 name  staff  6148 Jul 11 11:16 .DS_Store
-rw-r--r--@   1 name  staff   438 Jul 11 09:58 Makefile
lrwxr-xr-x@   1 name  staff    23 Jul 11 09:58 check_syscalls.c -> ../src/check_syscalls.c
lrwxr-xr-x@   1 name  staff    23 Jul 11 09:58 check_syscalls.h -> ../src/check_syscalls.h
-rw-r--r--@   1 name  staff   204 Jul 11 09:58 example.c
-rw-r--r--@   1 name  staff  9350 Jul 11 09:58 read_tree.c
-rw-r--r--@   1 name  staff  1176 Jul 11 09:58 read_tree.h
lrwxr-xr-x@   1 name  staff    20 Jul 11 09:58 stringparse.c -> ../src/stringparse.c
lrwxr-xr-x@   1 name  staff    20 Jul 11 09:58 stringparse.h -> ../src/stringparse.h
lrwxr-xr-x@   1 name  staff    17 Jul 11 09:58 strtonum.c -> ../src/strtonum.c
-rw-r--r--@   1 name  staff   885 Jul 11 09:58 zacc.c
5
  • Can you provide the output of ls -al on that "read_tree" directory? (And, does scp need a -r option to recursively copy this directory?)
    – jehad
    Commented Jul 11, 2016 at 15:56
  • 1
    Thanks for the edit/update. It's as I suspected, the files causing scp problems are ones that are symlinks. Scp does not follow symlinks. To fix this, you can create a tarball (seems like you have a small number of files, so shouldn't be a problem), and then scp the tarball. Do you need an answer on how to do this?
    – jehad
    Commented Jul 11, 2016 at 17:27
  • yes, I'm really new to programming so an explanation on how to create a tarball would be great!
    – Julia
    Commented Jul 11, 2016 at 17:39
  • I'll provide an answer to my comment above, but I think (having just read the latest manpage on scp), that the answer is a lot simpler; it's probably as I alluded to in my first comment, just use -r: scp -r read_tree <destination>. The manpage for scp says that the recursive option (-r) does follow symlinks.
    – jehad
    Commented Jul 11, 2016 at 17:44
  • Thanks! And I remembered that I have the .tar file for the read_tree folder so I was able to scp that over to my server, I'm all set now
    – Julia
    Commented Jul 11, 2016 at 17:47

1 Answer 1

4

Looks like scp on Mac does not follow symlinks, and your symlinked files are the ones causing the problem for you.

Two of many possible options are:
0. Use -r option of scp (manpage says it follows symlinks).
1. Tarball the files into one package, and send this single file over scp.
2. Copy the folder (dereferencing symlinks) and scp this new folder.

0) Recursive SCP option

Manpage of scp reads:

-r      Recursively copy entire directories.  Note that scp follows symbolic links encountered in the tree traversal.

Therefore, I expect the following to work:

scp -r read_tree <destination>

(However, I've not tested this on Mac, but it DOES work on GNU/Linux systems.)

1) Tarball Option

Package the folder, using tar -h, and send the one resulting file.

tar czhf read_tree.tgz read_tree
scp read_tree.tgz <destination>

Now, you can ssh into the remote server and unpack the files:

ssh <destination>
cd ~/Work/gmovie
tar xvf read_tree.tgz

2) Copy folder dereferencing symlinks

Make a copy of the original folder, but make sure symlinks are dereferenced to copy the original files. This can be achieved using cp -L:

cp -rLf read_tree read_tree_nosymlinks

Now scp the new folder:

scp -r read_tree_nosymlinks <destination>
2
  • I like your numbers starting from zero but calling { 0, 1, 2 } "two options" is kind of weird. Commented Jul 11, 2016 at 18:24
  • Because my zeroth option should just be the default way to use scp. Feels wrong to count it as an alternative option. :-)
    – jehad
    Commented Jul 11, 2016 at 18:25

You must log in to answer this question.

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