Beispiel #1
0
        public async Task <FileMetadata> GetFileMetadata(string serverPath, CancellationToken cancellationToken = default(CancellationToken))
        {
            serverPath = GetValidatedServerPath(serverPath);

            bool exists = await this.ftpClient.FileExistsAsync(serverPath, cancellationToken);

            if (!exists)
            {
                return(null);
            }

            var fileSize = await this.ftpClient.GetFileSizeAsync(serverPath, cancellationToken);

            var lastModifiedTime = await this.ftpClient.GetModifiedTimeAsync(serverPath, FtpDate.UTC, cancellationToken);

            var ret = new FileMetadata()
            {
                Uri  = new Uri(serverPath),
                Size = new DataSize(fileSize),
                LastChangeTimeUtc = lastModifiedTime
            };

            if (this.ftpClient.HasFeature(FtpCapability.HASH))
            {
                var ftpHash = await this.ftpClient.GetHashAsync(serverPath, cancellationToken);

                if (ftpHash.IsValid && !string.IsNullOrWhiteSpace(ftpHash.Value))
                {
                    ret.SetHashString(ftpHash.Value.Trim());
                }
            }
            else if (this.ftpClient.HasFeature(FtpCapability.XMD5))
            {
                var md5 = await this.ftpClient.GetMD5Async(serverPath, cancellationToken);

                if (!string.IsNullOrWhiteSpace(md5))
                {
                    ret.SetHashString(md5.Trim());
                }
            }

            return(ret);
        }