コード例 #1
0
        public static void Format(FtpCommandContext context, FileSystemInfo fileInfo, StringBuilder output)
        {
            var isFile = fileInfo is FileInfo;

            //Size
            output.AppendFormat("size={0};", isFile ? ((FileInfo)fileInfo).Length : 0);

            //Permission
            output.AppendFormat("perm={0}{1};", /* Can read */ isFile ? "r" : "el", /* Can write */ isFile ? "adfw" : "fpcm");

            //Type
            output.AppendFormat("type={0};", isFile ? "file" : "dir");

            //Create
            output.AppendFormat("create={0};", FtpDateUtils.FormatFtpDate(fileInfo.CreationTimeUtc));

            //Modify
            output.AppendFormat("modify={0};", FtpDateUtils.FormatFtpDate(fileInfo.LastWriteTimeUtc));

            //File name
            output.Append(DELIM);
            output.Append(fileInfo.Name);

            output.Append(NEWLINE);
        }
コード例 #2
0
        protected override object OnExecute(FtpCommandContext context)
        {
            context.Channel.CheckLogin();

            if (string.IsNullOrEmpty(context.Statement.Argument))
            {
                throw new SyntaxException();
            }

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

            context.Statement.Result = localPath;

            var info = new FileInfo(localPath);

            if (info.Exists)
            {
                var message = string.Format("213 {0}", FtpDateUtils.FormatFtpDate(info.LastWriteTimeUtc));
                context.Channel.Send(message);
                return(message);
            }

            throw new FileNotFoundException(path);
        }