sftp "cd" command to drive letter under cygwin

Corinna Vinschen vinschen at redhat.com
Wed Jan 9 06:13:09 EST 2013

On Jan  8 18:35, Peter Stuge wrote:
> Rick Patterson wrote:
> > When using sftp under cygwin, a "cd d:" attempt to change to the d:
> > drive, results in the following:
> > sftp> cd d:/
> > Couldn't canonicalise: No such file or directory.
> Your quote is "cd d:" but your command is "cd d:/" and those are
> different, so the above part is not very clear. Please clarify.
> > Since cygwin is supposed to support DOS paths as well as UNIX
> > paths, and the lcd is working, I thought I'd take a look at it.  I
> > found the make_absolute function in sftp.c was assuming an absolute
> > path starts with '/', but this is not true on Windows.   I think
> > the attached sftp.c.diff file is the fix, for your review, although
> > there is a behavior change I'd like to discuss below.
> Why would a behavior change be acceptable? Any change that you make
> must affect only Windows, and nothing else.
> > Previously, under Cygwin, in sftp, "cd d:" would not work, unless
> > there was a sub-directory in the current working directory that was
> > named "d:", which is allowed on the UNIX file system,  as ":" is an
> > allowed file name character.   With the proposed change, assuming
> > you want to "cd to d:" (where d: is a drive specification, and
> > therefore an absolute path),
> Stop right here. "d:" is *NOT* an absolute path on Windows systems.
> I'm sure you know that DOS and Windows both keep track of the current
> working directory per drive. "d:" changes working drive, but does NOT
> change current working directory either on the current driver or on d:.

> "d:\" and "d:/" are absolute paths.

This isn't correct.  Cygwin doesn't follow the lead of the CMD shell
here.  As a POSIX layer it only keeps track of a single CWD, in POSIX
and native NT notation.  Therefore, on Cygwin, d: is an absolute path,

However, DOS paths are only barely supported.  The right thing to do is
NOT to use DOS paths, but the equivalent POSIX path.  This is also
documented in the User's Guide:


> I'd suggest to look at the Cygwin source code to find out how exactly
> chdir() is implemented, and to make sftp-server implement the same
> algorithm. The client shouldn't have to be involved in this at all.
> (Unless Cygwin patches all shells to make multiple chdir() calls, but
> I find that somewhat unlikely.)

There's no reason to change anything.  Don't use DOS paths in Cygwin


Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

More information about the openssh-unix-dev mailing list