Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > scp and multiple files

scp and multiple files
Thread Tools
xsta
Fresh-Faced Recruit
Join Date: Nov 1999
Location: Helsinki, Finland
Status: Offline
Reply With Quote
Jan 10, 2002, 08:52 PM
 
How do i transfer multiple files with scp? Or a full content of a folder?
     
fitter
Senior User
Join Date: Jan 2000
Status: Offline
Reply With Quote
Jan 10, 2002, 10:21 PM
 
You can do this with the use of wild cards. At present scp doesn't allow for directory transfer (i.e., scp directory [email protected]:~), but you can get around it with wild cards, like so:

<font face = "courier">user% ls
thingone thingthree.txt thingtwo
user% scp * [email protected]:~/backup
thingone 100% |*****************************| 56 00:00
thingthree.txt 100% |*****************************| 7359 00:00
thingtwo 100% |*****************************| 345 00:00
</font>

But say you only want to scp thingtwo and thingthree.txt. How would you do that? Like so:

<font face = "courier">user% scp thingt* [email protected]:~/backup
thingthree.txt 100% |*****************************| 7359 00:00
thingtwo 100% |*****************************| 345 00:00
</font>

The asterisk matches anything, but the other letters must match exactly. That's why, in the second example, thingtwo and thingthree.txt are copied, but not thingone: it doesn't match the pattern.
     
xsta  (op)
Fresh-Faced Recruit
Join Date: Nov 1999
Location: Helsinki, Finland
Status: Offline
Reply With Quote
Jan 10, 2002, 11:04 PM
 
thanks
     
petej
Dedicated MacNNer
Join Date: Oct 2001
Location: Baltimore, MD, US
Status: Offline
Reply With Quote
Jan 10, 2002, 11:09 PM
 
If you want to copy multiple files from the remote machine, you need to escape the asterisk with a backslash, like this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>scp remotebox:somedirectory/\* .</font>[/code]
     
petej
Dedicated MacNNer
Join Date: Oct 2001
Location: Baltimore, MD, US
Status: Offline
Reply With Quote
Jan 10, 2002, 11:10 PM
 
Originally posted by xsta:
<STRONG>How do i transfer multiple files with scp? Or a full content of a folder?</STRONG>
The best way to do this is to use rsync over scp, instead of straight scp. rsync takes a little getting used to -- read the man page by issuing <font face = "courier">man rsync</font> to see how it's done. rsync will copy entire directory trees.
     
utidjian
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Jan 11, 2002, 02:36 AM
 
Ummm... scp does do directories, like so:

scp -r userid@somehost:somedir .

It will then recursively copy all files (and subfolders) in somedir to the local directory... placing the entire tree in a folder named somedir in the local directory.

For more useful info see man scp
-DU-...etc...
     
Paul McCann
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Jan 11, 2002, 06:04 AM
 
Ummm... scp does do directories, like so:

scp -r userid@somehost:somedir .

It will then recursively copy all files (and subfolders) in somedir to the local directory... placing the entire tree in a folder named somedir in the local directory.

For more useful info see man scp
True indeed, and very useful if you've got nice simple directory trees to copy: but (as usual), watch out for what it does with links and the like; results could be a bit nasty. "tar" can do things a little more carefully here.

(Of course, as mentioned above, using rsync is probably the nicest way to achieve remote copying/mirroring etc; trouble is, you may not have an rsync-enabled machine at the other end of the line. You might want to try buying the nice sysadmin a beer if that's the case (actually, a milkshake might be more effective if your sysadmin is anything like my old boss).)

To use tar to copy a local directory "togo" from your current working directory to a directory "togo" inside a directory "junk" in your home directory on the remote machine use

tar cf - togo | (ssh remote.machine.address "cd junk; tar xf -")

If you want to preserve permissions on the files add a "p" to the tar flags on both ends of hte pipe:

tar cpf - togo | (ssh remote.machine.address "cd junk; tar xpf -")

Actually this is a bit of a painful way to have to do things: if you're happy to dump the directory in your home directory on the remote machine you can avoid the spawning of the shell and instead use the more symmetric:

tar cpf - togo | ssh remote.machine.address tar xpf -

Hmm, with all this scp/tar/rsync loveliness floating around, why does anyone ever bother with sftp? (1) Because it's there, and (2) because you can leverage your hard-earned ftp knowledge, I suppose! Any other "advantages"?

Cheers,
Paul
     
utidjian
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Jan 11, 2002, 10:12 AM
 
Cool... though it may be desirable to recurse symlinks from the original... or not. tar does give you more control over that property. scp will faithfully recurse all symlinks.

rsync is definitely the way to go for some jobs. However, the problem I, and many others, have had with rsync is that it puts a tremendous load on both the transmitting and receiving machines. It also dies without complaint on very large "syncs" ( tens of gigs ).
-DU-...etc...
     
Wm. H. Magill
Fresh-Faced Recruit
Join Date: Mar 2002
Location: Philadelphia
Status: Offline
Reply With Quote
Mar 17, 2002, 12:20 AM
 
Ok... scp -r is recursive for directories. And wildcards work file for "pushing" files.
But what if you want to use scp to copy a list of files from a remote machine to a local machine...

Nominally something like:
scp user@remote-host:'{file1 file2 file3}' .
except that syntax doesn't work.

I've tried a couple of differnt shells but haven't found a working syntax to copy FROM a remote machine.
William H. Magill
Senior Systems Administrator
Information Services and Computing (ISC) Networking & Telecommunications
University of Pennsylvania
[email protected]
http://www.isc-net.upenn.edu/~magill/
     
davignes
Fresh-Faced Recruit
Join Date: Feb 2002
Location: Mississippi, USA
Status: Offline
Reply With Quote
Mar 20, 2002, 05:04 PM
 
Originally posted by Wm. H. Magill:
<STRONG>Ok... scp -r is recursive for directories. And wildcards work file for "pushing" files.
But what if you want to use scp to copy a list of files from a remote machine to a local machine...

Nominally something like:
scp user@remote-host:'{file1 file2 file3}' .
except that syntax doesn't work.

I've tried a couple of differnt shells but haven't found a working syntax to copy FROM a remote machine.</STRONG>

on a remote machine I touched three files
touch file1 file2 file3
then from my ibook I was able to scp them

[daniel:~] dv% scp dv@bart:file\* .
[email protected]'s password:
file1 100% |*****************************| 0 00:00
file2 100% |*****************************| 0 00:00
file3 100% |*****************************| 0 00:00

I used the \ b/c I was getting an error without them.
your shell tries to expand file* if you don'.
Pitr: Continue to kneel before me and
sayink "we are not worthy" many times. And bringink me coffee.
     
davignes
Fresh-Faced Recruit
Join Date: Feb 2002
Location: Mississippi, USA
Status: Offline
Reply With Quote
Mar 20, 2002, 11:40 PM
 
Originally posted by Wm. H. Magill:
<STRONG>Ok... scp -r is recursive for directories. And wildcards work file for "pushing" files.
But what if you want to use scp to copy a list of files from a remote machine to a local machine...

Nominally something like:
scp user@remote-host:'{file1 file2 file3}' .
except that syntax doesn't work.

I've tried a couple of differnt shells but haven't found a working syntax to copy FROM a remote machine.</STRONG>
also if you didn't want to use wildcards you couls just use
scp user@host:"file1 file2 fil3" .

that worked for me. On a Linux pc I touched three files
touch bob joe heh
and from my ibook using tcsh I was able to scp them fine.

[daniel:~] dv% scp [email protected]:"bob joe heh" .
[email protected]'s password:
bob 100% |*****************************| 0 00:00
joe 100% |*****************************| 0 00:00
heh 100% |*****************************| 0 00:00
Pitr: Continue to kneel before me and
sayink "we are not worthy" many times. And bringink me coffee.
     
msykes
Senior User
Join Date: Mar 2001
Location: Bay Area, CA
Status: Offline
Reply With Quote
Mar 21, 2002, 10:33 PM
 
Originally posted by Wm. H. Magill:
<STRONG>Ok... scp -r is recursive for directories. And wildcards work file for "pushing" files.
But what if you want to use scp to copy a list of files from a remote machine to a local machine...

Nominally something like:
scp user@remote-host:'{file1 file2 file3}' .
except that syntax doesn't work.

I've tried a couple of differnt shells but haven't found a working syntax to copy FROM a remote machine.</STRONG>
In my experience, you just need to add the double quotes (") around the files on the remote machine.

scp [email protected]:*.txt . doesn't work...

but

scp "[email protected]:*.txt" . does...
     
oeyvind
Senior User
Join Date: Mar 1999
Location: Somewhere near 1&ordm;18'N 103&ordm;50'E
Status: Offline
Reply With Quote
Mar 21, 2002, 11:13 PM
 
Originally posted by msykes:
<STRONG>

In my experience, you just need to add the double quotes (") around the files on the remote machine.

scp [email protected]:*.txt . doesn't work...

but

scp "[email protected]:*.txt" . does...</STRONG>
You can also use this:

scp [email protected]\\*.txt .

and for name with spaces,

scp [email protected]:this\\\ file\\\ tocopy .
     
(",)PB12
Junior Member
Join Date: Oct 2003
Location: Canada
Status: Offline
Reply With Quote
Jan 10, 2004, 08:07 PM
 
Hi guys I have a slightly different problem with scp. I'm trying to upload a file to the school's server using scp. But i'm constantly getting this error message.
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
lost connection

I'm pretty sure i've got the command right its something like this
scp localfilename loginName@host:~/public_html

Can someone help me? Thanks
     
Arkham_c
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jan 10, 2004, 10:41 PM
 
Originally posted by (",)PB12:
Hi guys I have a slightly different problem with scp. I'm trying to upload a file to the school's server using scp. But i'm constantly getting this error message.
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
lost connection

I'm pretty sure i've got the command right its something like this
scp localfilename loginName@host:~/public_html

Can someone help me? Thanks
Looks like maybe the remote server is running the old ssh1 instead of ssh2 or OpenSSH (which supports both).

You can force ssh and scp to use protocol version 1 with the -1 command line option. But SSH1 has several known vulnerabilities and should not be considered secure.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
spiky_dog
Mac Elite
Join Date: Dec 1999
Location: Plainview, NY
Status: Offline
Reply With Quote
Jan 12, 2004, 02:15 AM
 
Originally posted by (",)PB12:
Hi guys I have a slightly different problem with scp. I'm trying to upload a file to the school's server using scp. But i'm constantly getting this error message.
scp: warning: Executing scp1.
scp: FATAL: Executing ssh1 in compatibility mode failed (Check that scp1 is in your PATH).
lost connection

I'm pretty sure i've got the command right its something like this
scp localfilename loginName@host:~/public_html

Can someone help me? Thanks
i ran into this problem too, and had to use scp from the other end. ie log into the school server and scp the file off of your box:

log in
scp locallogin@yourcomp:/path/to/localfilename ./
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:42 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,