19

This is an edge use case, but I can't find a solution.

I want to copy the current directory ., without necessarily knowing or caring for its name, to a new directory. Using scp.

Bash does not seem to have a problem. e.g. cp -r . ../new-name will generate a new directory copy without any problems. But with scp -r . host:new-name i get scp: error: unexpected filename: .

The workarounds I'm using is to use rsync instead of scp, or to use scp -r ../current-name instead of scp -r .. But it would be nice to understand why the obvious way do not work with scp and if there's a simpler 'fix'.

Also note that I do no want to scp the contents of the current directory to another already-existing directory as in scp -r ./* host:existing-dir/. The goal is to copy the current directory itself to a new location (i.e. create a new directory)-

gcb
  • 4,891
  • 11
  • 56
  • 75

3 Answers3

30

According to this previous answer, the culprit is CVE-2017-20685; apparently, malicious remote hosts could exploit improper name validation, so support for . in paths for scp was disabled. The workaround is to replace . with $(pwd).

gnubeard
  • 1,224
12

You can expand . to the full path using something like ${PWD}, pwd or readlink -f .

scp -r "${PWD}" ${remote}:${dst_path}
Attie
  • 19,974
  • That only works correctly if the destination does not yet exist. If the destination already exists you get a new directory named after the source directory inside the destination. – tzs Aug 25 '21 at 01:13
3

scp ./* demo@test.com:/targetdir

I try ./* replate -r ./, it work