2

I'm writing a shell script for copying a file from a remote host to a local directory using scp. In case the target directory does not exist, I'm getting a misleading error message. i.e.:

scp user@remote-host:/path/to/existing/file /local/non-existing/directory/

The error I'm getting is:

/local/non-existing/directory/: Is a directory

which is puzzling... I would expect something like:

Directory /local/non-existing/directory/ does not exist
  1. Does it make sense to anybody or is it just me?
  2. Do you think it is a defect in scp?
  3. I'm running Ubuntu 14.04.3 LTS, is it the same in other operating systems?

migrated from stackoverflow.com Feb 12 '17 at 14:28

This question came from our site for professional and enthusiast programmers.

5

Bug

Found the related bug. It seems to be fixed in Ubuntu 14.04.5 (openssh 1:6.6p1-2ubuntu2.8)

There's an explanation on a Redhat bug report :

This problem is also in original openSSH and appears when you try to copy something into non-existing directory with existing parent directory. There is missing check for this boundary condition. Error message is thrown when scp process tries to write into above mentioned file, but this file ends with slash (which is interpretation for directory) and this is the reason for current error message.

Original answer

Cannot reproduce (tested on Ubuntu 14.04.5 LTS and Linux Mint 17)

  • If /local/non-existing/directory doesn't exist, scp fails with :

    /local/non-existing/directory: No such file or directory
    
  • If /local/existing/directory exist, scp copies file to /local/existing/directory/file

  • If remote-host:/path/to/existing/file is a directory, scp fails with :

    scp: file: not a regular file
    

Troubleshooting

ssh user@remote-host "file /path/to/existing/file"

should give you information about the remote file (or possibly directory).

file /local/non-existing/directory/

should give you information about the local directory

mkdir -p /local/non-existing/directory/

wil recursively create the directory, and any parent if necessary.

After mkdir -p, if file is really a file and /local/non-existing/directory/ is really a directory, your scp command should work.

  • What O/S are you on? – vstrom coder Feb 12 '17 at 11:01
  • See update, 14.04.5 – Eric Duminil Feb 12 '17 at 11:03
  • I'm not trying to troubleshoot it, since I already know that the local non-existing directory is the issue. I'm just puzzled by the misleading error message. – vstrom coder Feb 12 '17 at 11:14
  • Still. Does it work after creating the /local/non-existing/directory/? – Eric Duminil Feb 12 '17 at 11:17
  • Yes, it does ::: – vstrom coder Feb 12 '17 at 11:21

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.