Renci.SshNet.Sftp.SftpSession.RequestWrite C# (CSharp) Method

RequestWrite() public method

Performs SSH_FXP_WRITE request.
public RequestWrite ( byte handle, ulong serverOffset, byte data, int offset, int length, AutoResetEvent wait, Action writeCompleted = null ) : void
handle byte The handle.
serverOffset ulong The the zero-based offset (in bytes) relative to the beginning of the file that the write must start at.
data byte The buffer holding the data to write.
offset int the zero-based offset in at which to begin taking bytes to write.
length int The length (in bytes) of the data to write.
wait System.Threading.AutoResetEvent The wait event handle if needed.
writeCompleted Action The callback to invoke when the write has completed.
return void
        public void RequestWrite(byte[] handle,
                                 ulong serverOffset,
                                 byte[] data,
                                 int offset,
                                 int length,
                                 AutoResetEvent wait,
                                 Action<SftpStatusResponse> writeCompleted = null)
        {
            SshException exception = null;

            var request = new SftpWriteRequest(ProtocolVersion, NextRequestId, handle, serverOffset, data, offset,
                length, response =>
                    {
                        if (writeCompleted != null)
                        {
                            writeCompleted(response);
                        }

                        exception = GetSftpException(response);
                        if (wait != null)
                            wait.Set();
                    });

            SendRequest(request);

            if (wait != null)
                WaitOnHandle(wait, OperationTimeout);

            if (exception != null)
            {
                throw exception;
            }
        }