コード例 #1
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        private FtpItem BuildItem(Match match, string path)
        {
            int     code;
            long    size;
            FtpItem item = new FtpDirectory();

            if (match.Groups["dir"].Value == "-" ||
                match.Groups["dir"].Value == string.Empty)
            {
                item = new FtpFile();
            }
            else
            {
                item = new FtpDirectory();
            }

            item.FileCode    = int.TryParse(match.Groups["filecode"].Value, out code) ? code : -1;
            item.Group       = match.Groups["group"].Value;
            item.Host        = Host;
            item.Name        = match.Groups["name"].Value;
            item.Owner       = match.Groups["owner"].Value;
            item.Path        = path;
            item.Permissions = match.Groups["permission"].Value;
            item.Size        = long.TryParse(match.Groups["size"].Value, out size) ? size : 0;
            item.Timestamp   = ParseTimestamp(match);

            return(item);
        }
コード例 #2
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        /// <summary>
        /// Renames a file on the server.
        /// </summary>
        /// <param name="file">The <see cref="FtpFile"/> to rename.</param>
        /// <param name="newName">The new file name to use.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="file"/> argument is null.
        /// </exception>
        public void RenameFile(FtpFile file, string newName)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file", "The FtpFile can not be null");
            }

            if (string.IsNullOrWhiteSpace(file.Name))
            {
                throw new UriFormatException("The FtpFile's Name property can not be empty");
            }

            RenameFile(file.Path + file.Name, newName);
        }
コード例 #3
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        /// <summary>
        /// Downloads a file from the server.
        /// </summary>
        /// <param name="file">The <see cref="FtpFile"/> to download.</param>
        /// <param name="localFilePath">The path to the local download file.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="file"/> argument is null.
        /// </exception>
        /// <exception cref="UriFormatException">
        /// The <paramref name="file"/> name property is empty.
        /// </exception>
        public void DownloadFile(FtpFile file, string localFilePath)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file", "The FtpFile can not be null");
            }

            if (string.IsNullOrWhiteSpace(file.Name))
            {
                throw new UriFormatException("The FtpFile's Name property can not be empty");
            }

            DownloadFile(file.Path + file.Name, localFilePath);
        }
コード例 #4
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        /// <summary>
        /// Gets the server files last write time.
        /// </summary>
        /// <param name="file">The FtpFile to get the last write time of.</param>
        /// <returns>A nullable <see cref="System.DateTime"/> representing the file's last write time.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="file"/> argument is null.
        /// </exception>
        /// <exception cref="UriFormatException">
        /// The <paramref name="file"/> name property is empty.
        /// </exception>
        public DateTime?LastWriteTime(FtpFile file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file", "The FtpItem can not be null");
            }

            if (string.IsNullOrWhiteSpace(file.Name))
            {
                throw new UriFormatException("The FtpItem's Name property can not be empty");
            }

            file.Timestamp = LastWriteTime(file.Path + file.Name);
            return(file.Timestamp);
        }
コード例 #5
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        private FtpItem BuildItem( Match match, string path )
        {
            int code;
            long size;
            FtpItem item = new FtpDirectory();

            if( match.Groups[ "dir" ].Value == "-" ||
                match.Groups[ "dir" ].Value == string.Empty ) {
                item = new FtpFile();
            }
            else {
                item = new FtpDirectory();
            }

            item.FileCode = int.TryParse( match.Groups[ "filecode" ].Value, out code ) ? code : -1;
            item.Group = match.Groups[ "group" ].Value;
            item.Host = Host;
            item.Name = match.Groups[ "name" ].Value;
            item.Owner = match.Groups[ "owner" ].Value;
            item.Path = path;
            item.Permissions = match.Groups[ "permission" ].Value;
            item.Size = long.TryParse( match.Groups[ "size" ].Value, out size ) ? size : 0;
            item.Timestamp = ParseTimestamp( match );

            return item;
        }
コード例 #6
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        /// <summary>
        /// Uploads a local file to the server.
        /// </summary>
        /// <param name="file">The <see cref="FtpFile"/> to upload to.</param>
        /// <param name="localFilePath">The path to the local file.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="file"/> argument is null.
        /// </exception>
        /// <exception cref="UriFormatException">
        /// The <paramref name="file"/> name property is empty.
        /// </exception>
        public void UploadFile( FtpFile file, string localFilePath )
        {
            if( file == null ) {
                throw new ArgumentNullException( "file", "The FtpFile can not be null" );
            }

            if( string.IsNullOrWhiteSpace( file.Name ) ) {
                throw new UriFormatException( "The FtpFile's Name property can not be empty" );
            }

            UploadFile( file.Path + file.Name, localFilePath );
        }
コード例 #7
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        /// <summary>
        /// Gets the server files last write time.
        /// </summary>
        /// <param name="file">The FtpFile to get the last write time of.</param>
        /// <returns>A nullable <see cref="System.DateTime"/> representing the file's last write time.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="file"/> argument is null.
        /// </exception>
        /// <exception cref="UriFormatException">
        /// The <paramref name="file"/> name property is empty.
        /// </exception>
        public DateTime? LastWriteTime( FtpFile file )
        {
            if( file == null ) {
                throw new ArgumentNullException( "file", "The FtpItem can not be null" );
            }

            if( string.IsNullOrWhiteSpace( file.Name ) ) {
                throw new UriFormatException( "The FtpItem's Name property can not be empty" );
            }

            file.Timestamp = LastWriteTime( file.Path + file.Name );
            return file.Timestamp;
        }
コード例 #8
0
ファイル: FtpConnection.cs プロジェクト: belsrc/ftplib
        /// <summary>
        /// Deletes a file from the server.
        /// </summary>
        /// <param name="file">The <see cref="FtpFile"/> to delete.</param>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="file"/> argument is null.
        /// </exception>
        public void DeleteFile( FtpFile file )
        {
            if( file == null ) {
                throw new ArgumentNullException( "file", "The FtpFile can not be null" );
            }

            if( string.IsNullOrWhiteSpace( file.Name ) ) {
                throw new UriFormatException( "The FtpFile's Name property can not be empty" );
            }

            DeleteFile( file.Path + file.Name );
        }