0 votes
by (120 points)

I use the GetList( "Data.txt" ) method to get file to be downloaded from SFTP. SftpItem.Path contains double file name. I assume, Path must be like "Data.txt", but it contains "Data.txt/Data.txt". Is it bug or expected behavior?

Example:

using( var sftpClient = new Sftp() )
{
    sftpClient.LogWriter = new FileLogWriter( "C:\\temp\\sftp.log", Rebex.LogLevel.Debug );

    sftpClient.Connect( "somesftp.com" );

    sftpClient.Login( "login", "password" );

    var files = sftpClient.GetList( "Data.txt" );

    Console.WriteLine( "Name: " +  files[ 0 ].Name );
    Console.WriteLine( "Path: " +  files[ 0 ].Path );
    Console.WriteLine( "IsDirectory: " +  files[ 0 ].IsDirectory );
    Console.WriteLine( "IsFile: " +  files[ 0 ].IsFile );
}

Console output:

Name: Data.txt
Path: Data.txt/Data.txt
IsDirectory: False
IsFile: True

Log(sensitive data is modified):

2024-06-10 13:55:39.804 Opening log file.
2024-06-10 13:55:39.807 INFO FileLogWriter(1)[1] Info: Assembly: Rebex.Common 7.0.8865 for .NET Framework 4.6-4.8
2024-06-10 13:55:39.810 INFO FileLogWriter(1)[1] Info: Platform: Windows 6.2.9200 32-bit; CLR: 4.0.30319.42000
2024-06-10 13:55:39.810 DEBUG FileLogWriter(1)[1] Info: Culture: fi; Windows-1252
2024-06-10 13:55:39.833 INFO Sftp(1)[1] Info: Connecting to somesftp.com:22 using Sftp.
2024-06-10 13:55:39.834 INFO Sftp(1)[1] Info: Assembly: Rebex.Sftp 7.0.8865 for .NET Framework 4.6-4.8 (Trial)
2024-06-10 13:55:39.834 INFO Sftp(1)[1] Info: Platform: Windows 6.2.9200 32-bit; CLR: 4.0.30319.42000
2024-06-10 13:55:39.834 DEBUG Sftp(1)[1] Info: Culture: fi; Windows-1252
2024-06-10 13:55:39.842 DEBUG Sftp(1)[1] Proxy: Resolving 'somesftp.com'.
2024-06-10 13:55:39.856 DEBUG Sftp(1)[1] Proxy: Connecting to XXX.XXX.XXX.XXX:22 (no proxy).
2024-06-10 13:55:39.928 DEBUG Sftp(1)[1] Proxy: Connection established.
2024-06-10 13:55:40.001 DEBUG Sftp(1)[1] SSH: Server is 'SSH-2.0-2.0'.
2024-06-10 13:55:40.006 INFO Sftp(1)[1] SSH: Negotiation started.
2024-06-10 13:55:40.150 DEBUG Sftp(1)[1] SSH: Negotiating key.
2024-06-10 13:55:40.237 DEBUG Sftp(1)[1] SSH: Validating 'ssh-rsa' signature.
2024-06-10 13:55:40.257 DEBUG Sftp(1)[1] SSH: Received 2048-bit RSA server key (minimum allowed size is 1023 bits).
2024-06-10 13:55:40.334 INFO Sftp(1)[1] SSH: Negotiation finished.
2024-06-10 13:55:40.334 INFO Sftp(1)[1] Info: Server: SSH-2.0-2.0
2024-06-10 13:55:40.334 INFO Sftp(1)[1] Info: Fingerprint (MD5): XXXXXXXXXXX
2024-06-10 13:55:40.335 INFO Sftp(1)[1] Info: Fingerprint (SHA-256): XXXXXXXXXXX
2024-06-10 13:55:40.335 INFO Sftp(1)[1] Info: Cipher info: SSH 2.0, ecdh-sha2-nistp256, ssh-rsa, aes256-ctr/aes256-ctr, hmac-sha2-256/hmac-sha2-256
2024-06-10 13:55:40.493 DEBUG Sftp(1)[1] SSH: Allowed authentication methods for 'xxxxxxxx': password.
2024-06-10 13:55:40.494 DEBUG Sftp(1)[1] SSH: Trying password authentication for 'xxxxxxxx'.
2024-06-10 13:55:40.645 DEBUG Sftp(1)[1] SSH: Authentication successful.
2024-06-10 13:55:40.648 DEBUG Sftp(1)[1] SSH: Opening channel 'session' (initial window size: 131072, max packet size: 129024).
2024-06-10 13:55:40.722 DEBUG Sftp(1)[1] SSH: Requesting subsystem 'sftp'.
2024-06-10 13:55:40.799 INFO Sftp(1)[1] Command: SSH_FXP_INIT (4)
2024-06-10 13:55:40.871 INFO Sftp(1)[1] Response: SSH_FXP_VERSION (4, 1 extension)
2024-06-10 13:55:40.872 INFO Sftp(1)[1] Info: Using SFTP v4 on a Windows-like platform.
2024-06-10 13:55:40.873 INFO Sftp(1)[1] Command: SSH_FXP_REALPATH (1, '.')
2024-06-10 13:55:40.954 INFO Sftp(1)[1] Response: SSH_FXP_NAME (1, '/')
2024-06-10 13:55:40.954 INFO Sftp(1)[1] Info: Home directory is '/'.
2024-06-10 13:55:40.960 INFO Sftp(1)[1] Command: SSH_FXP_OPENDIR (2, '/Data.txt')
2024-06-10 13:55:41.038 INFO Sftp(1)[1] Response: SSH_FXP_HANDLE (2, 0x0)
2024-06-10 13:55:41.039 INFO Sftp(1)[1] Command: SSH_FXP_READDIR (3, 0x0)
2024-06-10 13:55:41.109 INFO Sftp(1)[1] Response: SSH_FXP_NAME (3, 1 item)
2024-06-10 13:55:41.113 DEBUG Sftp(1)[1] Info: Item: -rw-------   1 user     group       903028 Jun 10 09:45 Data.txt
2024-06-10 13:55:41.113 INFO Sftp(1)[1] Command: SSH_FXP_READDIR (4, 0x0)
2024-06-10 13:55:41.185 INFO Sftp(1)[1] Response: SSH_FXP_STATUS (4, 1, 'End of file.')
2024-06-10 13:55:41.186 INFO Sftp(1)[1] Command: SSH_FXP_CLOSE (5, 0x0)
2024-06-10 13:55:41.257 INFO Sftp(1)[1] Response: SSH_FXP_STATUS (5, 0, 'Success.')
Applies to: Rebex SFTP

1 Answer

0 votes
by (70.4k points)

The experienced behavior is correct from client's point of view.

The client issued SSH_FXP_OPENDIR (2, '/Data.txt') command. Server replied with SSH_FXP_HANDLE (2, 0x0) success, which indicates that a directory named '/Data.txt' exists and is readable. Then the client listed remote directory with SSH_FXP_READDIR (3, 0x0) command and the server replied with SSH_FXP_NAME (3, 1 item) single item. Then the directory was closed.

The Path property was constructed from remote directory ("/Data.txt") and received item name ("Data.txt").

The RFC draft for SFTP v4 states:

The SSHFXPOPENDIR opens a directory for reading. ... This will return an error if the path does not specify a directory or if the directory is not readable.

The Rebex SFTP client does not verify whether the server is lying or not.

If you want to receive information about a single file, consider using GetInfo() method instead of GetList():

var item = sftpClient.GetInfo("/Data.txt");
...