0 votes
by (270 points)
edited

The following exception occurs when attempting to upload a file to an SFTP server when the authenticated user does not have write permission for the remote path.

I would expect an SftpException with a SftpErrorCode.PermissionDenied error code not a system exception.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Rebex.Net.SftpCore.Close(SftpHandle handle, Boolean ignoreErrors)
   at Rebex.Net.Sftp.PutFileInternal(SftpOpenMode mode, Object state, String remotePath, Stream sourceStream, Int64 remoteOffset, Int64 length)
   at Rebex.Net.Sftp.PutFile(Stream sourceStream, String remotePath)
   at Idintl.Net.FileTransferProtocol.SftpDropper.DropFile(String rsaFingerprint, String address, Int32 port, String username, String password, String fileDirectory, String fileName, Stream fileStream, String triggerDirectory, String triggerFileName, Stream triggerFileStream)

If the authenticated user has write permission this exception doesn't occur and the file is uploaded.

Here is the code I am using with some error handling removed for clarity.


Sftp client = new Sftp();
using (client)
{
    client.Connect(address, port);

client.Login(username, password);

string filePath = CreateFilePath(fileDirectory, fileName);

client.PutFile(fileStream, filePath);
}

None of the parameters are null or empty strings, the fileStream is a MemoryStream of about 200kB. fileDirectory specifies a valid path on the SFTP server, but that directory does not have write permission for user username.

Applies to: Rebex SFTP

1 Answer

0 votes
by (73.5k points)
edited
 
Best answer

Please log into http://www.rebex.net/protected, download the latest version of the component (it is 2.0.4086.0 for today) and give it a try.

If the issue persists, please create a communication log using the Sftp object's LogWriter property, as described here, and either add it to your forum post or mail it to support@rebex.net. We might be able to tell more once we have the log.

by (270 points)
edited

I never got around to checking with 2.0.4086.0 but I can confirm that it is resolved in 2.0.4546.0.

...