0 votes
by (160 points)
edited

Hi, I am using Rebex .Net to perform an SFTP file transfer from client to server. Previously we were using FTP and are upgrading it to SFTP. The code has an event handler for the batch transfer progress. This is used to determine if the transfer was finally successfull.

I am using the batch transfer mode. Client is windows, server is unix. Initial testing with single files succeeded. Multiple files seems to succeed, but the log shows a SSH_FXP_STATUS response from the server that the file was not found (for all files in the batch). This is before the transfer. Why does this happen? why the need for STAT / file attribs?

see the SSH_FXP_STAT for the TransferFile

update: I did a few tests with one file, two files, with just putFile and putFiles, I found that putFiles will always have this SSH_FXP_STAT and it fails from the second file. Note, it succeeds for the first file ! All this before the transfer.

How can it intend to find the file on the server before the transfer? and how is it that the first file returns with ATRS? What am I doing wrong?

sample log:

2014-07-09 06:30:41.807 DEBUG Sftp(1) SSH: Authentication successful.
2014-07-09 06:30:41.847 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_OPEN (24 bytes).
    5A-00-00-00-07-73-65-73-73-69-6F-6E-00-00-00-00-00-02-00-00-00-00-40-00
2014-07-09 06:30:41.847 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_IGNORE (5 bytes).
    02-00-00-00-00
2014-07-09 06:30:41.847 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_CHANNEL_OPEN_CONFIRMATION (17 bytes).
    5B-00-00-00-00-00-00-00-00-00-01-86-A0-00-00-40-00
2014-07-09 06:30:41.897 DEBUG Sftp(1) SSH: Requesting subsystem 'sftp'.
2014-07-09 06:30:41.907 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_REQUEST (27 bytes).
    62-00-00-00-00-00-00-00-09-73-75-62-73-79-73-74-65-6D-01-00-00-00-04-73
    66-74-70
2014-07-09 06:30:41.907 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_IGNORE (5 bytes).
    02-00-00-00-00
2014-07-09 06:30:41.907 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_CHANNEL_SUCCESS (5 bytes).
    63-00-00-00-00
2014-07-09 06:30:41.937 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_DATA (18 bytes).
    5E-00-00-00-00-00-00-00-09-00-00-00-05-01-00-00-00-04
2014-07-09 06:30:41.947 INFO Sftp(1) Command: SSH_FXP_INIT (4)
2014-07-09 06:30:41.967 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_IGNORE (5 bytes).
    02-00-00-00-00
2014-07-09 06:30:41.967 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_CHANNEL_DATA (71 bytes).
    5E-00-00-00-00-00-00-00-3E-00-00-00-3A-02-00-00-00-03-00-00-00-13-6E-65
    77-6C-69-6E-65-40-76-61-6E-64-79-6B-65-2E-63-6F-6D-00-00-00-01-0A-00-00
    00-0D-75-6D-61-73-6B-40-73-73-68-2E-63-6F-6D-00-00-00-04-00-00-00-12
2014-07-09 06:30:41.997 INFO Sftp(1) Response: SSH_FXP_VERSION (3, 2 extensions)
2014-07-09 06:30:41.997 INFO Sftp(1) Info: Using SFTP v3.
2014-07-09 06:30:42.007 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_DATA (23 bytes).
    5E-00-00-00-00-00-00-00-0E-00-00-00-0A-10-00-00-00-01-00-00-00-01-2E
2014-07-09 06:30:42.017 INFO Sftp(1) Command: SSH_FXP_REALPATH (1, '.')
2014-07-09 06:30:42.017 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_IGNORE (5 bytes).
    02-00-00-00-00
2014-07-09 06:30:42.017 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_CHANNEL_DATA (90 bytes).
    5E-00-00-00-00-00-00-00-51-00-00-00-4D-68-00-00-00-01-00-00-00-01-00-00
    00-1C-2F-70-72-6F-64-2F-75-73-65-72-73-2F-65-78-74-64-61-74-61-2F-71-63
    63-74-72-66-74-70-00-00-00-1C-2F-70-72-6F-64-2F-75-73-65-72-73-2F-65-78
    74-64-61-74-61-2F-71-63-63-74-72-66-74-70-00-00-00-00
2014-07-09 06:30:42.037 INFO Sftp(1) Response: SSH_FXP_NAME (1, 1 item)
2014-07-09 06:30:42.037 INFO Sftp(1) Info: Current directory is '/abcp/users/sftpuser'.
2014-07-09 06:30:42.037 INFO Sftp(2) SFTP Login to host successful: Ready
2014-07-09 06:30:42.047 INFO Sftp(1) DateTime: 7/9/2014 6:30:42 AM
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.ServerName: 10.xx.xx.xx
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.ServerPort: 22
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.ServerType: Unix
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.State: Ready
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Timeout: 60000
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.TransferType: Ascii
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.UserName: xxxxxxx
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Fingerprint: xxxxxxxxx
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.LocalEndPoint: xxx.xx.xx.xx:xx
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Options: UseLargeBuffers
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Proxy: none
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.RemoteEndPoint: xx.xx.xx.xx:xx
2014-07-09 06:30:42.047 INFO Sftp(1) Encoding: System.Text.SBCSCodePageEncoding
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session:: Rebex.Net.SshSession
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Authenticated: True
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Cipher: SSH 2.0, Diffie-Hellman-Group1-SHA1, DSS, aes256-cbc/aes256-cbc, SHA1/SHA1
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Connected: True
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.ServerIdentification: SSH-2.0-4.4.8.21 SSH Secure Shell
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Parameters: Rebex.Net.SshParameters
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Parameters.Compression: False
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Parameters.EncryptionAlgorithms: Any
2014-07-09 06:30:42.047 INFO Sftp(1) SFTPClient.Session.Parameters.Options: None
2014-07-09 06:30:42.157 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_DATA (77 bytes).
    5E-00-00-00-00-00-00-00-44-00-00-00-40-11-00-00-00-02-00-00-00-37-2F-70
    72-6F-64-2F-68-6F-6D-65-30-31-2F-64-61-74-61-2F-73-65-72-69-61-6C-2F-70
    72-6F-70-68-69-74-2F-70-72-6F-70-68-69-74-5F-63-61-73-65-5F-6D-67-6D-74
    2F-74-65-6D-70
2014-07-09 06:30:42.167 INFO Sftp(1) Command: SSH_FXP_STAT (2, '/abcp/home01/data/dataone')
2014-07-09 06:30:42.167 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_IGNORE (5 bytes).
    02-00-00-00-00
2014-07-09 06:30:42.167 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_CHANNEL_DATA (50 bytes).
    5E-00-00-00-00-00-00-00-29-00-00-00-25-69-00-00-00-02-00-00-00-0F-00-00
    00-00-00-06-C0-00-00-00-A2-92-00-00-1E-72-00-00-45-FD-53-BD-15-6D-53-BC
    F6-75
2014-07-09 06:30:42.167 INFO Sftp(1) Response: SSH_FXP_ATTRS (2)
2014-07-09 06:30:42.317 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_DATA (107 bytes).
    5E-00-00-00-00-00-00-00-62-00-00-00-5E-11-00-00-00-03-00-00-00-55-2F-70
    72-6F-64-2F-68-6F-6D-65-30-31-2F-64-61-74-61-2F-73-65-72-69-61-6C-2F-70
    72-6F-70-68-69-74-2F-70-72-6F-70-68-69-74-5F-63-61-73-65-5F-6D-67-6D-74
    2F-74-65-6D-70-2F-32-30-31-34-30-37-30-38-30-30-30-30-30-30-5F-74-62-6C
    41-63-63-6F-75-6E-74-2E-64-61-74
2014-07-09 06:30:42.317 INFO Sftp(1) Command: SSH_FXP_STAT (3, '/abcp/home01/data/dataone'/20140708_transferfile.txt')
2014-07-09 06:30:42.317 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_IGNORE (5 bytes).
    02-00-00-00-00
2014-07-09 06:30:42.317 VERBOSE Sftp(1) SSH: Received packet SSH_MSG_CHANNEL_DATA (102 bytes).
    5E-00-00-00-00-00-00-00-5D-00-00-00-59-65-00-00-00-03-00-00-00-02-00-00
    00-46-73-79-73-65-72-72-3A-20-4E-6F-20-73-75-63-68-20-66-69-6C-65-20-6F
    72-20-64-69-72-65-63-74-6F-72-79-2C-20-66-69-6C-65-3A-20-32-30-31-34-30
    37-30-38-30-30-30-30-30-30-5F-74-62-6C-41-63-63-6F-75-6E-74-2E-64-61-74
    00-00-00-02-65-6E
2014-07-09 06:30:42.317 INFO Sftp(1) Response: SSH_FXP_STATUS (3, 2, 'syserr: No such file or directory, file: 20140708_transferfile.txt')
2014-07-09 06:30:42.357 VERBOSE Sftp(1) SSH: Sending packet SSH_MSG_CHANNEL_DATA (115 bytes).
    5E-00-00-00-00-00-00-00-6A-00-00-00-66-03-00-00-00-04-00-00-00
Applies to: Rebex SFTP

1 Answer

+1 vote
by (144k points)
edited
 
Best answer

> Why does this happen? why the need for STAT / file attribs?

In multi-file mode (Upload or PutFiles methods), Rebex SFTP uses SSH_FXP_STAT command to determine whether each item exists and whether it's a file or directory. The result affects the subsequent action. If the item doesn't exists, the server replies with SSH_FXP_STATUS response with error code 2 and a server-specific message.

> How can it intend to find the file on the server before the transfer?

Upload (or PutFiles) methods detect whether the files already exist at the server and throw an exception in that case (by default). Just try uploading the same set of files twice to see this in action.

> And how is it that the first file returns with ATRS?

The first item seems to be the target directory, not a file. The multi-file methods check that as well to make sure the target directory exists.

> What am I doing wrong?

I don't think you are doing anything wrong. However, if you would like the Sftp object to simply perform the action you specified and nothing else, then that's what the PutFile method is for.

...