Renci.SshNet.Common.PipeStream.Write C# (CSharp) Method

Write() public method

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
An I/O error occurs. The stream does not support writing. Methods were called after the stream was closed. is null. The sum of offset and count is greater than the buffer length. offset or count is negative.
public Write ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes. This method copies count bytes from buffer to the current stream.
offset int The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count int The number of bytes to be written to the current stream.
return void
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");
            if (offset + count > buffer.Length)
                throw new ArgumentException("The sum of offset and count is greater than the buffer length.");
            if (offset < 0 || count < 0)
                throw new ArgumentOutOfRangeException("offset", "offset or count is negative.");
            if (_isDisposed)
                throw CreateObjectDisposedException();
            if (count == 0)
                return;

            lock (_buffer)
            {
                // wait until the buffer isn't full
                while (Length >= _maxBufferLength)
                    Monitor.Wait(_buffer);

                _isFlushed = false; // if it were flushed before, it soon will not be.

                // queue up the buffer data
                for (var i = offset; i < offset + count; i++)
                {
                    _buffer.Enqueue(buffer[i]);
                }

                Monitor.Pulse(_buffer); // signal that write has occurred
            }
        }

Usage Example

コード例 #1
0
ファイル: ScpClient.NET.cs プロジェクト: trebor-salim/SSH.NET
        /// <summary>
        /// Uploads the specified directory to the remote host.
        /// </summary>
        /// <param name="directoryInfo">The directory info.</param>
        /// <param name="path">The path.</param>
        /// <exception cref="ArgumentNullException">fileSystemInfo</exception>
        /// <exception cref="ArgumentException"><paramref name="path"/> is null or empty.</exception>
        public void Upload(DirectoryInfo directoryInfo, string path)
        {
            if (directoryInfo == null)
                throw new ArgumentNullException("directoryInfo");
            if (string.IsNullOrEmpty(path))
                throw new ArgumentException("path");

            using (var input = new PipeStream())
            using (var channel = Session.CreateChannelSession())
            {
                channel.DataReceived += delegate(object sender, ChannelDataEventArgs e)
                {
                    input.Write(e.Data, 0, e.Data.Length);
                    input.Flush();
                };

                channel.Open();

                //  Send channel command request
                channel.SendExecRequest(string.Format("scp -rt \"{0}\"", path));
                CheckReturnCode(input);

                InternalSetTimestamp(channel, input, directoryInfo.LastWriteTimeUtc, directoryInfo.LastAccessTimeUtc);
                SendData(channel, string.Format("D0755 0 {0}\n", Path.GetFileName(path)));
                CheckReturnCode(input);

                InternalUpload(channel, input, directoryInfo);

                SendData(channel, "E\n");
                CheckReturnCode(input);

                channel.Close();
            }
        }
All Usage Examples Of Renci.SshNet.Common.PipeStream::Write