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)-


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).

  • How about remote CWD? Is there a similar "trick" for that? – David Balažic May 4 '20 at 20:43
  • PS: You mean "$(pwd)", right? (I just had a failure because the Windows 10 version of scp trips on filenames that contain spaces) – David Balažic May 4 '20 at 20:44

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

scp -r "${PWD}" ${remote}:${dst_path}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.