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();
string filePath = CreateFilePath(fileDirectory, fileName);
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