Esempio n. 1
0
        private bool TryGetHandle(uint requestId, string name, out SftpHandle handle)
        {
            if (handles.ContainsKey(name))
            {
                handle = handles[name];
                return(true);
            }
            else
            {
                handle = null;

                var status = new StatusPacket
                {
                    Id           = requestId,
                    StatusCode   = StatusPacket.Failure,
                    ErrorMessage = "unknown channel"
                };

                Send(status);

                return(false);
            }
        }
Esempio n. 2
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);
            }
        }