Bug 2809 - SCP gives very confusing / wrong error message when -p is used incorrectly
Summary: SCP gives very confusing / wrong error message when -p is used incorrectly
Status: CLOSED WONTFIX
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: scp (show other bugs)
Version: 7.5p1
Hardware: Other Linux
: P5 normal
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-08 14:12 AEDT by Niklas Hambuechen
Modified: 2018-04-06 12:26 AEST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Niklas Hambuechen 2017-12-08 14:12:06 AEDT
When the user assumes `-p` does the same for scp as it does for ssh, funny things happen:

  touch myfile
  scp -p 22 myfile targetmachine:targetfile

The above prints "scp: targetfile: No such file or directory", which, while true (there is no file called "targetfile" on the host -- the users intent was to put it there), is a very confusing error message.

The problem here is that `-p` doesn't accept an argument for scp as it does for ssh, and so "22" is treated as a file name. It is the file "22" that doesn't exist.

Let's

  touch ~/targetfile

on `targetmachine`. What happens then?

  $ scp -p 22 myfile zh.nh2.me:targetfile
  scp: targetfile: Not a directory

Certainly true, targetfile is not a directory. Nevertheless, not quite the error message the user would hope for.

What if we make `targetfile` a directory then (`rm ~/targetfile && mkdir targetdir` on targethost)?

  $ scp -p 22 myfile zh.nh2.me:targetdir
  22: No such file or directory
  myfile                     100%    0     0.0KB/s   00:00

Finally an error message that points out what the user did wrong.

Would it be possible to improve scp's error messages, such that for this very common error of using `-p` incorrectly, the earlier examples point out more helpfully to the user that "22" doesn't exist?

Thanks!
Comment 1 Damien Miller 2018-01-05 13:51:08 AEDT
It isn't possible to fix this generally without completely rewriting getopt() and we aren't prepared to do that, sorry.
Comment 2 Damien Miller 2018-04-06 12:26:40 AEST
Close all resolved bugs after release of OpenSSH 7.7.