Exemplo n.º 1
0
        /// <summary>
        /// Obtains the size of the file in the file system.
        /// </summary>
        /// <param name="arguments">Command arguments</param>
        /// <param name="session">FTP session context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>FTP server response to send to the client.</returns>
        protected override async Task <IResponse> Handle(string arguments, FtpSessionState session, CancellationToken cancellation)
        {
            if (String.IsNullOrEmpty(arguments))
            {
                return(FtpResponses.ParameterSyntaxError);
            }

            if (session.TransferType != FileTransferType.Image)
            {
                // Only return size in Image file transfer mode
                return(FtpResponses.FileUnavailable);
            }

            var itemPath = session.CurrentDirectory.Clone();

            FileSystemItem item = null;

            if (itemPath.Navigate(arguments))
            {
                item = await session.FileSystem.GetItem(itemPath, cancellation);
            }

            if (item == null || item.IsDirectory)
            {
                return(FtpResponses.FileUnavailable);
            }

            return(FtpResponses.FileStatus(item.Size.ToString(CultureInfo.InvariantCulture)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new directory in the file system.
        /// </summary>
        /// <param name="arguments">Command arguments</param>
        /// <param name="session">FTP session context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>FTP server response to send to the client.</returns>
        protected override async Task <IResponse> Handle(string arguments, FtpSessionState session, CancellationToken cancellation)
        {
            if (String.IsNullOrEmpty(arguments))
            {
                return(FtpResponses.ParameterSyntaxError);
            }

            var itemPath = session.CurrentDirectory.Clone();

            if (itemPath.Navigate(arguments) && await session.FileSystem.CreateDirectory(itemPath, cancellation))
            {
                var itemPathString = itemPath.ToString();
                session.Logger.WriteInfo(TraceResources.CreatedDirectoryFormat, itemPathString);
                return(FtpResponses.Path(itemPathString, session.PathEncoding));
            }

            return(FtpResponses.FileUnavailable);
        }
        /// <summary>
        /// Obtains the last modification time of the file system item.
        /// </summary>
        /// <param name="arguments">Command arguments</param>
        /// <param name="session">FTP session context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>FTP server response to send to the client.</returns>
        protected override async Task <IResponse> Handle(string arguments, FtpSessionState session, CancellationToken cancellation)
        {
            if (String.IsNullOrEmpty(arguments))
            {
                return(FtpResponses.ParameterSyntaxError);
            }

            var itemPath = session.CurrentDirectory.Clone();

            FileSystemItem item = null;

            if (itemPath.Navigate(arguments))
            {
                item = await session.FileSystem.GetItem(itemPath, cancellation);
            }

            if (item == null)
            {
                return(FtpResponses.FileUnavailable);
            }

            return(FtpResponses.FileStatus(
                       item.LastModifiedTime.ToString(TimestampFormat, CultureInfo.InvariantCulture)));
        }