Portable OpenSSH on Linux: confusing error message with scp

Leah Neukirchen leah at vuxu.org
Wed Apr 6 06:14:23 AEST 2022


Hi,

With OpenSSH 8.9p1 (and earlier) and scp server-side on Linux 5.13,
one gets a very confusing error message when the target directory ends
with / and *does not exist*:

	% scp /etc/issue localhost:/usr/foobar/
	scp: /usr/foobar/: Is a directory

stracing shows:

[pid 32671] stat("/usr/foobar/", 0x7fff4aaa5fd0) = -1 ENOENT (No such file or directory)
[pid 32671] openat(AT_FDCWD, "/usr/foobar/", O_WRONLY|O_CREAT, 0644) = -1 EISDIR (Is a directory)

scp.c does rougly:

                exists = stat(np, &stb) == 0;
                /* ... stuff elided ... */
                if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) == -1) {
bad:                    run_err("%s: %s", np, strerror(errno));
                        continue;
                }

open(2) says:

       EISDIR pathname refers to a directory and the access requested involved
              writing (that is, O_WRONLY or O_RDWR is set).

Apparently, on OpenBSD it prints "No such file or directory" instead.

I wonder if adding

		if (errno == EISDIR)
			errno = ENOENT;

would be a suitable override, or perhaps you have a better idea.
But printing something is directory when it isn't is confusing. :)

cu,
-- 
Leah Neukirchen  <leah at vuxu.org>  https://leahneukirchen.org/


More information about the openssh-unix-dev mailing list