Need to transfer files between 2 UNIX servers, with same folder permission

I need to transfer directories/files between 2 Unix servers, with same folder permission.
I tried scp, but it retains the the permissions, but changes the owner of the directory/file to the user used to copy them to the destination. I don't want that to happen.
If possible without any other additional installation of tools.

Thanks,
Pandee

If your requirement is to change the owner of directory & files within it, then try below command after transferring:-

ssh $user@$host "chown -R user <absolute path of dir>"

where user is user to which ownership needs to be given. I hope your have setup ssh-keys between these servers.

1 Like

Hi Bipin,

Thanks for your quick reply.

Actually I want to move a directory as a whole from one server to another server, provided each of the files/sub-directories under that has the same permission and owner as that of the source.

Use rsync like below :

rsync -avz /folders/  user@targethost:/destination/

or with ssh :

rsync -avz -e ssh  /folders/  user@targethost:/destination/

Make sure you hav the same set of users owning the files in the source folders present in the destinations else the owner:group would be changed to uid and gid of the source.

Hi Ningy,

for using rsync, should I need to install the tool?
I'm working on SunOS 5.10 Generic_144488-10 sun4v sparc SUNW,Sun-Fire-T200
Could you please let me know the procedure to install or configure it, if needed?

Thanks,

is it not installed already ?

pkginfo |grep rsync

IF not check for it on the installation pack CD/DVD or download it from sunfreeware .

Also using tar and ssh to retain permissions.

tar cvf - dir/ | ssh server2 "cd /dest/dir && tar xvf -"