sftp "cd" command to drive letter under cygwin

Rick Patterson rick.patterson at hotmail.com
Wed Jan 9 02:25:43 EST 2013


Hello.

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.

It can only be done by using a cygdrive-type path:
sftp> cd /cygdrive/d
sftp> pwd
Remote working directory: /cygdrive/d
sftp>

yet a local cd (lcd) works fine. "lcd d:" works, and then lpwd prints a cygdrive path (which is fine).
sftp> lcd d:/
sftp> lpwd
Local working directory: /cygdrive/d

I submitted this problem to the cygwin forum, but perhaps that was not the correct place:   http://cygwin.com/ml/cygwin/2012-12/msg00160.html

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.

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), the cd now works to the absolute path "d:" thereby supporting DOS paths.  However,  it also changes the previous behavior,  as "cd d:" will now not go to the sub-directory "d:" if it exists, unless it is qualified as "./d:"    A "d:" needs to be treated firstly as an absolute path before a sub-directory.    This allows the previously ambiguous behavior to still work if required, but only by qualifying it as a sub-directory.

I agree a batter fix might be that "if d:" does not exist as a drive letter, but there is a "d:" sub-directory, then cd to the d: sub-directory.  This fix as proposed does not do this.  I've tested the cd command under the Cygwin command line shell - it does appear to be able to conditionally cd to d: as a DOS drive if it exists, ignoring  a d: sub-directory that exists.  However, if x: does not exist as a drive letter, but does exist as a sub-directory then it does cd to x:.   I believe an extra call from the sftp client to the sftp server would be required to do the conditional cd in sftp to be consistent with the Cygwin command line, but this would be beyond my abilities.

Rick 		 	   		  


More information about the openssh-unix-dev mailing list