Пример #1
0
        private void HandlePacket(OpenDirPacket packet)
        {
            logger.LogDebug("Processing OpenDir SFTP packet, Id={Id}, Path='{Path}'.", packet.Id, packet.Path);

            // If they cannot read the directory, respond with a status packet.
            if (!fileSystem.CanReadDirectory(packet.Path))
            {
                var status = new StatusPacket
                {
                    Id           = packet.Id,
                    StatusCode   = StatusPacket.PermissionDenied,
                    ErrorMessage = "permission denied"
                };

                Send(status);
            }
            else
            {
                // Create a new channel
                // TODO - use a factory to create the handle, so it can get its own logger
                var handleId = Interlocked.Increment(ref nextChannelId).ToString();
                var handle   = new SftpHandle(this, handleId, fileSystem, logger);

                handles.Add(handleId, handle);

                handle.OpenDir(packet.Path);

                var response = new HandlePacket
                {
                    Id     = packet.Id,
                    Handle = handle.Name
                };

                Send(response);
            }
        }