示例#1
0
        private void WriteFileInfo(FtpCommandContext context, FileSystemInfo fileInfo)
        {
            var result = FtpMlstFileFormater.Format(context, fileInfo);

            var data = context.Channel.Encoding.GetBytes(result);

            context.Channel.DataChannel.Send(data, 0, data.Length);
        }
示例#2
0
        protected override object OnExecute(FtpCommandContext context)
        {
            context.Channel.CheckLogin();

            try
            {
                var path = string.Empty;
                if (!string.IsNullOrWhiteSpace(context.Statement.Argument))
                {
                    path = context.Statement.Argument;
                }

                if (string.IsNullOrWhiteSpace(path))
                {
                    path = context.Channel.CurrentDir;
                }

                var localPath = context.Channel.MapVirtualPathToLocalPath(path);
                context.Statement.Result = localPath;

                FileSystemInfo fileInfo;

                if (File.Exists(localPath))
                {
                    fileInfo = new FileInfo(localPath);
                }
                else if (Directory.Exists(localPath))
                {
                    fileInfo = new DirectoryInfo(localPath);
                }
                else
                {
                    throw new FileNotFoundException(path);
                }

                var message = string.Format("250-Listing {0}\r\n{1}250 END", path, FtpMlstFileFormater.Format(context, fileInfo));
                context.Channel.Send(message);
                return(message);
            }
            catch (IOException e)
            {
                throw new InternalException(e.Message);
            }
        }