LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-01-2017, 11:17 AM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian Stretch
Posts: 1,110

Rep: Reputation: 85
scp -rp does not preserve attributes


I am trying to copy an entire remote directory. I want to preserve at least modification times:

scp -P229 -rp user@10.0.3.1:/path/to/directory ./

I've done this before and it used to work. Now, the files are all transferred with the current time and date.

What am I doing wrong?
 
Old 09-01-2017, 01:09 PM   #2
dejank
Member
 
Registered: May 2016
Location: Belgrade, Serbia
Distribution: Debian
Posts: 229

Rep: Reputation: Disabled
Not sure, that p should do the job. But I'm far from expert on scp. Have you thought on using something else to copy those files? It is not that scp is really efficient in copping large number of files, it kinda has to establish contact for every file separately, which sure slows things down. You might have more luck in using rsync, or even tar over ssh. For example from machine where files you want to copy are:

Code:
tar zcf - /things/to/copy | ssh user@adress 'tar zxf -'
And you can use -C option for destination. And from machine you want to receive files:

Code:
ssh user@adress 'tar zcf - /things/to/copy/' | tar zxf -
For rsync you have many tutorials around.
 
Old 09-06-2017, 04:03 AM   #3
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 553

Rep: Reputation: 277Reputation: 277Reputation: 277
Have you tried it the other way round? First ssh into 10.0.3.1 and copy it from there using scp -pr.
 
Old 09-06-2017, 09:57 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042Reputation: 1042
SCP is not the best option for copying directories. It has also problems with directory names containing spaces.

Use rsync. It never fails. Note however that if you try to copy files which have a different owner on the remote computer they will be owned by you on your local computer. If that is not the intention, issue the command as root. So you will write files on your local machine which root permissions.

In your example, the correct rsync command would be:
Code:
rsync -av --port=229 user@10.0.3.1:/path/to/directory/ ./
The slash behind directory is relevant. If it is there, it will not create ./directory on your local machine. If there is no slash, ./directory will be created. In either case copying is recursive.

The -a option will recursively copy the source directory, maintaining permissions and file creation times. There are a hundred more options to add to rsync. Check the man page if you need something more exotic.

jlinkels

Last edited by jlinkels; 09-06-2017 at 09:59 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell scp works perfectly, Net::SCP::Expect calls timing out - reasons? EnderX Programming 1 04-27-2013 01:35 AM
Explain the attributes "links" in cp --preserve=links bigmac15 Linux - Newbie 1 04-14-2013 07:06 PM
Centos 6.3 host+guest: try scp to guest: scp cmd not found. ssh ok chrism01 Linux - Virtualization and Cloud 3 08-24-2012 01:52 AM
scp does not work and gives the following error message: scp: FATAL: Executing ssh1 i akay Linux - Networking 16 09-28-2008 11:41 PM
scp -p doesn't preserve? taiwf Linux - General 4 03-05-2006 08:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration