Ejemplo n.º 1
0
        /// <summary>
        /// 非同期送信コールバック
        /// </summary>
        /// <param name="ar"></param>
        private void SendCallBack(IAsyncResult ar)
        {
            // オブジェクト変換
            SshClientSendStream stream = (SshClientSendStream)ar.AsyncState;

            // 送信完了
            stream.ShellStream.EndWrite(ar);

            // ロギング
            this.Logger.InfoFormat("送信データ - {0:#,0} byte:\n{1}", stream.Stream.Length, Common.Diagnostics.Debug.Dump(1, stream.Stream));

            // 送信通知
            this.OnSendNotify.Set();

            // イベント呼出
            if (this.OnSend != null)
            {
                // イベントパラメータ生成
                SshClientSendEventArgs eventArgs = new SshClientSendEventArgs()
                {
                    ConnectionInfo = stream.ConnectionInfo,
                    Size           = (int)stream.Stream.Length,
                    Stream         = stream.Stream,
                };

                // イベント呼出し
                this.OnSend(this, eventArgs);
            }

            // ShellStreamフラッシュ
            stream.ShellStream.Flush();

            // 送信通知リセット
            this.OnSendNotify.Reset();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 非同期送信
        /// </summary>
        /// <param name="stream"></param>
        public void SendAsync(MemoryStream stream)
        {
            // 接続中か?
            if (!this.m_Client.IsConnected)
            {
                // 例外
                throw new SshClientException("接続状態(SSH)ではありません");
            }

            // 送信用Stream生成
            SshClientSendStream sendStream = new SshClientSendStream();

            sendStream.ConnectionInfo = this.m_ConnectionInfo;
            sendStream.IPEndPoint     = this.m_IPEndPoint;
            sendStream.ShellStream    = this.m_ShellStream;
            sendStream.Size           = (int)stream.Length;
            sendStream.Stream         = stream;
            sendStream.SshClient      = this.m_Client;

            // 非同期送信
            IAsyncResult _result = this.m_ShellStream.BeginWrite(stream.ToArray(), 0, stream.ToArray().Length, new AsyncCallback(this.SendCallBack), sendStream);
        }