I'm using scp to upload a directory to a remote server. However, if the remote server does not have a "target" directory of the same name, I get a "No such file" error. Note that this is not an issue of the target directory not existing (in the following example, the target is the home directory of the remote server). It simply doesn't share a name with the sent directory.

Failed directory upload example:

$ mkdir test_local 
$ touch test_local/test_local.txt 
$ scp -r ./test_local [email protected]:
> scp: realpath ./test_local: No such file
> scp: upload "./test_local": path canonicalization failed
> scp: failed to upload directory ./test_local to .

However, if I create an empty target directory with the same name on the remote machine ([email protected]:~/test_local), the command does work and successfully updates the target directory with the contents of the local directory.

It's my understanding that scp should not require an empty "target" directory of the same name to exist, so why is this the case here?

I am using MacOS 13.0.1, and the remote host is using Rocky Linux 8.6 (Green Obsidian).

  • What OS is in the remote host, and does the remote host have something unusual in its setup? For example, if the remote host has SELinux and the user's home directory at the remote host is in a location other than /home, the administrator of the remote system need to apply the appropriate SELinux permissions to the home directory and its parent directory too. If this step was missed, you might see unexpected restrictions.
    – telcoM
    Commented Jan 2, 2023 at 16:57
  • Remote host OS is Rocky Linux 8.6 (Green Obsidian). Thanks for the tip, I'll ask the administrator about the setup.
    – Elias
    Commented Jan 2, 2023 at 17:01
  • It seems to work for other users of the same remote host, so I thought it may be an issue from my end.
    – Elias
    Commented Jan 2, 2023 at 17:03
  • same fault with subdirectories. What gives a function like recursive copy no sens Commented Jul 1 at 13:17

1 Answer 1


Newest version of scp (starting from ssh 9.0.0) use SFTP protocol for copying. For sftp that problem is very known. The solution is to use -O flag for scp, i.e. scp -O -r

I have found this solution here.

  • Weirdly the issue seems to have resolved itself without my doing anything, so I can't test this solution. But thanks!
    – Elias
    Commented Jan 26, 2023 at 21:36
  • It works. The "-O" is minus O capital letter (not zero). Commented Apr 9 at 19:39

You must log in to answer this question.

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