/// <summary> /// Downloads a document at a specified relativeUrl to a temporary file. /// </summary> /// <param name="documentSummary"></param> /// <returns>The location of the downloaded file.</returns> public static string DownloadFile(AttachedDocumentSummary documentSummary) { Platform.CheckForNullReference(documentSummary, "documentSummary"); // if already cached locally, return local file name var tempFile = TempFileManager.Instance.GetFile(documentSummary.DocumentRef); if (!string.IsNullOrEmpty(tempFile)) { return(tempFile); } var ftpFileTransfer = new FtpFileTransfer( AttachedDocumentSettings.Default.FtpUserId, AttachedDocumentSettings.Default.FtpPassword, AttachedDocumentSettings.Default.FtpBaseUrl, AttachedDocumentSettings.Default.FtpPassiveMode); var fullUrl = new Uri(ftpFileTransfer.BaseUri, documentSummary.ContentUrl); var fileExtension = Path.GetExtension(fullUrl.LocalPath).Trim('.'); var localFilePath = TempFileManager.Instance.CreateFile(documentSummary.DocumentRef, fileExtension, TimeSpan.FromSeconds(AttachedDocumentSettings.Default.DownloadCacheTimeToLive)); ftpFileTransfer.Download(new FileTransferRequest(fullUrl, localFilePath)); return(localFilePath); }
/// <summary> /// Gets the document at the specified URI, returning a local path to a copy of the document. /// </summary> /// <param name="url"></param> /// <returns></returns> public string GetDocument(string url) { var fullUrl = new Uri(_ftpFileTransfer.BaseUri, url); var localFilePath = Path.Combine(_tempPath, Path.GetFileName(fullUrl.LocalPath)); _ftpFileTransfer.Download(new FileTransferRequest(fullUrl, localFilePath)); return(localFilePath); }