Exemple #1
0
        public SftpHandleTests()
        {
            handle = new SftpHandle(sftp.Object, HandleName, vfs.Object, logger.Object);

            sftp.Setup(x => x.Send(It.IsAny <SftpPacket>()))
            .Callback <SftpPacket>(x => sentPacket = x);
        }
Exemple #2
0
        public void Send(SftpPacket packet)
        {
            logger.LogDebug("Sending SFTP {Type} packet. {Details}", packet.PacketType, packet.Details());

            // TODO - too much copying of bytes down inside here!
            channel.SendData(packet.GetBytes());
        }
Exemple #3
0
        private bool ProcessPacket(SftpPacket p)
        {
            switch (p.SftpCode)
            {
            case SftpMessageCode.SSH_FXP_DATA:
            {
                var msg = (SftpData)p;
                WaitHandles[msg.RequestId].Set(msg);
                return(true);
            }

            case SftpMessageCode.SSH_FXP_VERSION:
                waitHandle.Set();
                return(true);

            case SftpMessageCode.SSH_FXP_HANDLE:
            {
                var msg = (SftpHandle)p;
                WaitHandles[msg.RequestId].Set(msg);
                return(true);
            }

            case SftpMessageCode.SSH_FXP_NAME:
            {
                var msg = (SftpName)p;
                WaitHandles[msg.RequestId].Set(msg);
                return(true);
            }

            case SftpMessageCode.SSH_FXP_ATTRS:
            {
                var msg = (SftpAttrs)p;
                WaitHandles[msg.RequestId].Set(msg);
                return(true);
            }

            case SftpMessageCode.SSH_FXP_STATUS:
            {
                var msg = (SftpStatus)p;
                switch (msg.Status)
                {
                case SftpStatusCode.SSH_FX_NO_SUCH_FILE:
                    WaitHandles[msg.RequestId].Set(new FileNotFoundException(msg.Message));
                    return(true);

                case SftpStatusCode.SSH_FX_PERMISSION_DENIED:
                case SftpStatusCode.SSH_FX_FAILURE:
                    WaitHandles[msg.RequestId].Set(new IOException(msg.Message));
                    return(true);

                case SftpStatusCode.SSH_FX_OK:
                    WaitHandles[msg.RequestId].Set();
                    return(true);

                case SftpStatusCode.SSH_FX_EOF:
                    WaitHandles[msg.RequestId].Set();
                    return(true);
                }
                return(false);
            }
            }
            return(false);
        }