Scp the current dir `.` to another name
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)-
Solution 1:
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)
.
Solution 2:
You can expand .
to the full path using something like ${PWD}
, pwd
or readlink -f .
scp -r "${PWD}" ${remote}:${dst_path}