Create directory fails for SFTP protocol if directory name contains unicode characters

0 votes
asked Mar 11, 2013 by DS1 (160 points)
edited Mar 11, 2013

Hello, When I am trying to create a directory on a FTP server using the SFTP protocol and the directory name contains unicode character, I get an exception saying the directory already exists.

This happens for specific characters like 'ϕ'. Following is the log I am getting:

Error Info: Rebex.Net.SftpException: Failure; Directory or file already exists. at gbMKS.PEQpz.eCVvJZ(1dRwomZ , Type ) at gbMKS.PEQpz.NIt1A(String , ZD5WJ ) at Rebex.Net.Sftp.1kDyXdZ(String , ZD5WJ )

How can I create directories using unicode characters?

1 Answer

0 votes
answered Mar 11, 2013 by Tomas Knopp (58,890 points)
edited Mar 11, 2013

Hello,

in Sftp version 3 the RFC did not define the encoding to be used, whereas in SFTP version 4 UTF8 is the defined one. So sometimes in version 3 one must manually assing the correct encoding to the SFTP client.

To solve the problem, please create a log as described here with LogLevel.Info. Please look for the line which identifies the SFTP version (should be either v3 or v4).

Here is an example of such log, the SFTP version line is below in bold:

2013-03-11 15:57:53.267 Opening log file.
2013-03-11 15:57:53.279 INFO Sftp(1)[1] Info: Connecting to tcharles.local:22 using Sftp 3.0.4700.0.
2013-03-11 15:57:53.308 INFO Sftp(1)[1] SSH: Negotiation started.
2013-03-11 15:57:53.444 INFO Sftp(1)[1] SSH: Negotiation finished.
2013-03-11 15:57:53.445 INFO Sftp(1)[1] Info: Server: SSH-2.0-OpenSSH_6.0p1 Debian-3
2013-03-11 15:57:53.445 INFO Sftp(1)[1] Info: Fingerprint: e2:29:05:cd:7a:59:ee:03:fa:03:f5:72:61:77:e3:1c
2013-03-11 15:57:53.446 INFO Sftp(1)[1] Info: Cipher info: SSH 2.0, DiffieHellmanGroupExchangeSHA256, DSS, aes256-ctr/aes256-ctr, hmac-sha1/hmac-sha1
2013-03-11 15:57:53.459 INFO Sftp(1)[1] SSH: Received banner: Debian GNU/Linux 7.0 
2013-03-11 15:57:53.527 INFO Sftp(1)[1] Command: SSH_FXP_INIT (4)
2013-03-11 15:57:53.541 INFO Sftp(1)[1] Response: SSH_FXP_VERSION (3, 4 extensions)

2013-03-11 15:57:53.542 INFO Sftp(1)[1] Info: Using SFTP v3 on a Unix-like platform.

If your server uses SFTP version 4, unicode characters should work just fine. In case of version 3, please try adding this line of code into your program:

sftp.Encoding = Encoding.UTF8;

and test if you are able to create directories with unicode characters now.

...