9

I'm running scp and copying a folder from remote server, I'm running with -rl , so i see the files being copy, is it possible to skip current file some way?

3 Answers 3

11

No you can't. But you can stop scp and use rsync instead. It will copy only the differences left from the partial copy and you can exclude any files or dirs you don't want to transfer.

rsync -avP -e ssh --exclude=somefile --exclude=somedir ./localdir/ user@server:remotedir/
2
  • 2
    This is useful, yes, but unfortunately it doesn't answer the question that was asked.
    – Emmaly
    Dec 9, 2012 at 13:15
  • 10
    It answers the question perfectly; the question asks if it is possible to do something and this answer answers "no". It then provides a helpful, on-topic alternative. Feb 22, 2016 at 2:13
1

No, not with -r or any other syntax that performs multiple file transfers within one scp command.

That said, scp also follows the UNIX paradigm: write programs that provide simple, precise functionality that can be chained together in interesting ways. This means it would be possible to write a loop that interactively performs individual invocations of the command, one per file. You would then be able to break out of the individual commands as they're being run. (Ctrl-C)

The code for this is being left as an exercise to the reader, but the need for this loop to execute within an interactive shell must be emphasized. Breaking out of a non-interactive shell would terminate the entire job.

0

Yes you can!

Let's list the remote directory and copy each file separately. Then hit ctrl-c for each file that you don't want to copy:

OLD_IFS="$IFS"
IFS=$'\n'
for file in `ssh user@host ls /remote/directory/`
  do echo user@host:/remote/directory/$file /local/directory/
done;
IFS="$OLD_IFS"

OLD_IFS is here to handle files with spaces in them.

2
  • Where do you put this? How do you call it? Apr 30, 2018 at 18:12
  • @StatsSorceress I believe this should be saved into a shell script and executed Jan 6 at 2:24

You must log in to answer this question.

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