0 votes
by (150 points)

We need to send a test file to a customer via SFTP.

We are using the PutFile method which returns the correct number of bytes transferred (28) and does not throw an exception except the file is never transferred. The test file does not exist in the remote directory and does not appear when searching over sftp via the GetItems method.

This logic has worked for numerous customers but is now failing for this one.


    using (var client = new Rebex.Net.Sftp())
{
    client.LogWriter = new Rebex.ConsoleLogWriter(Rebex.LogLevel.Debug);

    client.Connect("*****.***.*****.com", 2032);
    client.Login("*********", "*******");

    const string testFileName = "test.txt";
    const string testFileContent = "File upload test successful.";
    const string ReceiveDirectory = "Receive";
    var remoteFilePath = Path.Combine(ReceiveDirectory, testFileName).Replace("\\", "/");

    var bytes = Encoding.Default.GetBytes(testFileContent);
    using (var stream = new MemoryStream(bytes))
    {
        var bytesTransferred = client.PutFile(stream, remoteFilePath);

        // value = 28
        bytesTransferred.Dump();
    }

    // value = false
    client.FileExists(remoteFilePath).Dump();
}

Logs:

2017-08-15 09:57:29.525 DEBUG Sftp(31)[16] SSH: Authentication successful.
2017-08-15 09:57:29.694 DEBUG Sftp(31)[16] SSH: Requesting subsystem 'sftp'.
2017-08-15 09:57:29.863 INFO Sftp(31)[16] Command: SSH_FXP_INIT (4)
2017-08-15 09:57:30.031 INFO Sftp(31)[16] Response: SSH_FXP_VERSION (3, 1 extension)
2017-08-15 09:57:30.031 INFO Sftp(31)[16] Info: Using SFTP v3.
2017-08-15 09:57:30.032 INFO Sftp(31)[16] Command: SSH_FXP_REALPATH (1, '.')
2017-08-15 09:57:30.206 INFO Sftp(31)[16] Response: SSH_FXP_NAME (1, 1 item)
2017-08-15 09:57:30.206 INFO Sftp(31)[16] Info: Current directory is '/'.
2017-08-15 09:57:30.206 INFO Sftp(31)[16] Command: SSH_FXP_OPEN (2, '/Receive/test.txt', 26)
2017-08-15 09:57:30.480 INFO Sftp(31)[16] Response: SSH_FXP_HANDLE (2, 0x30)
2017-08-15 09:57:30.480 DEBUG Sftp(31)[16] Command: SSH_FXP_WRITE (3, 0x30, 0, 28 bytes)
2017-08-15 09:57:30.653 DEBUG Sftp(31)[16] Response: SSH_FXP_STATUS (3, 0, 'The write completed successfully')
2017-08-15 09:57:30.653 INFO Sftp(31)[16] Command: SSH_FXP_CLOSE (4, 0x30)
2017-08-15 09:57:30.911 INFO Sftp(31)[16] Response: SSH_FXP_STATUS (4, 0, 'The operation completed')
28 // dumped out by linq pad
2017-08-15 09:57:30.913 INFO Sftp(31)[16] Command: SSH_FXP_STAT (5, '/Receive/test.txt')
2017-08-15 09:57:31.159 INFO Sftp(31)[16] Response: SSH_FXP_STATUS (5, 2, 'The message [/Receive/test.txt] is not extractable!')
False //dumped out by linq pad

Thanks in advance for any help figuring this out.

Applies to: Rebex SFTP

1 Answer

0 votes
by (147k points)
selected by
 
Best answer

The log indicates that the file was actually transferred to the server successfully. If any error occured at the server-side, the server has not report this to the client.

However, the 'The message [/Receive/test.txt] is not extractable!' reponse to SSH_FXP_STAT command (which is used by Sftp object's ExistsFile, GetFileLength and other methods) suggests that the server is not actually an ordinary SFTP file server, but rather an SFTP gateway to some kind of messaging system. It does not state that "file does not exist" (which is indicated by the status code), but that a "message is not extractable", whatever that means.

It's quite possible that the server treats all uploaded files as some kind of "messages" and processes them immediately, without making it possible to download them (or "extract" in it's jargon). Unfortunately, we are not familiar with this server - to determine what is actually going on, you would have to consult its maintainer or vendor.

by (150 points)
Thanks for the quick reply, we will look into the customers sftp setup.
...