0

I need to transfer all *.png from different directories from a remote server BUT preserving the full path of each .png file because all .png files have the same name.

scp -r -e server:coverages/K4me3/*/pos/output/*/*.png Desktop/

While coping it rewrites already existing .png files because the names od them are the same in different directories. I want to preserve the full directory path,s o that when copying, the .png files are copied within their own directories.

Alina
  • 2,191
  • 3
  • 33
  • 68
  • This is partially answered here http://askubuntu.com/questions/56262/whats-the-command-for-ssh-to-find-files-which-png-and-download-them – ergonaut Sep 18 '15 at 15:30
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. Also see [Where do I post questions about Dev Ops?](http://meta.stackexchange.com/q/134306). – jww Apr 16 '16 at 02:19

2 Answers2

1

SCP doesn't preserve the paths of files on its own, as you have discovered.

You'll probably want to use rsync to do this, since rsync does preserve paths

I think the command would be:

rsync -a -r -v -z server_config:/path/to/root/directory/on/server [destination_folder]

This is the reverse of this question: scp a folder to a remote system keeping the directory layout


Alternatively, and as the comments suggest, you can write a script to get all of the files or lower level directories (with absolute path) and call an scp transfer on each of them. Here is a script that I at one point used to copy files in this way:

#!/usr/bin/env python
from multiprocessing.dummy import Pool
from subprocess import call
from functools import partial

root = #  Root Directory
files = [
    root + # Sub 1,
    root + # Sub 2,
    root + # Sub 3,
    root + # Sub etc,
]
command_s = "scp -r -v -c arcfour -F /path/to/.ssh/config Server:"
command_e = " Output_Dir/"
max_processes = 4  
# Transfer the files 4 at a time because my computer is busy with other stuff
cmds = []

for filename in files:
    cmds.append(command_s + filename + command_e)

pool = Pool(max_processes)
for i, returncode in enumerate(pool.imap(partial(call, shell=True), cmds)):
    if returncode != 0:
        print ("%d command failed: %d" % (i, returncode))
Community
  • 1
  • 1
0

Here is an answer to preserve directory structure and copy just the png files from a server to a local system based on ssh.

ssh user@server 'find /server/path -name "*.png" -print0 | xargs -0 tar -cO' | tar -xfv - -C .

Source: Link

Balan
  • 23
  • 3