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);
        }
Example #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);
        }
Example #3
0
        protected override object OnExecute(FtpCommandContext context)
        {
            const string MESSAGE = "213 Date/time changed OK.";

            context.Channel.CheckLogin();

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

                var arguments = context.Statement.Argument.Split(new[]
                {
                    ' '
                }, 2);
                if (arguments.Length != 2)
                {
                    throw new SyntaxException();
                }

                var dateTime = FtpDateUtils.ParseFtpDate(arguments[0]);
                var filePath = context.Channel.MapVirtualPathToLocalPath(arguments[1]);

                var fileInfo = new FileInfo(filePath);
                if (!fileInfo.Exists)
                {
                    throw new FileNotFoundException(arguments[1]);
                }

                fileInfo.LastWriteTimeUtc = dateTime;

                context.Channel.Send(MESSAGE);

                return(MESSAGE);
            }
            catch (FtpException)
            {
                throw;
            }
            catch (Exception)
            {
                throw new InternalException("");
            }
        }
 private static string GetLastModified(FileSystemInfo file)
 {
     return(FtpDateUtils.FormatUnixDate(file.LastWriteTimeUtc));
 }