Legacy Pipeline Atlas worker-1snapshot 2026-07-15

MDClarity · task primitive

Download

Overview

DownloadTask downloads files from remote FTP or SFTP servers to local directories. It supports parallel downloading, file archiving on the remote server, deletion after transfer, and checked transfers to ensure files are not actively being written before download.

Use this task when: You need to retrieve data files from external partners, vendors, or remote servers via FTP/SFTP protocols.

Don't use this task when:


Parameters

Parameter Type Required Default Description
Host string Yes - The FTP/SFTP server hostname or IP address
Port int No 22 The server port (22 for SFTP, 21 for FTP)
Username string Yes - Authentication username for the server
Password string Yes - Authentication password for the server
Protocol ProtocolSubset No Sftp Transfer protocol: Sftp or Ftp
ConnectionTimeoutInSeconds int No 120 Maximum time to wait for server connection
RemoteDirectory string No "/" Directory on remote server to search for files
RemoteFileName string No null Specific filename or pattern to download (e.g., "*.csv")
LocalDirectory string Yes - Local directory where files will be saved
RemoteArchiveDirectory string No null If set, files are moved to this remote directory after successful download
MaxDownloaders int No 10 Maximum number of concurrent download threads
DeleteOnSuccess bool No false Delete files from remote server after successful download
UseCheckedTransfer bool No false Wait for files to stop changing before downloading (prevents partial transfers)

Execution Flow

YesNoNoYesYesNoYesNoYesNoYesNoStart DownloadTaskCreate DownloadClient andDownloadParamsValidate parametersValidation errors?ThrowValidationFailedExceptionCreate session with servercredentialsFind files matchingRemoteFileName inRemoteDirectoryAny files found?Log 'No files found' and exitAdd files to downloadqueueStart up toMaxDownloadersconcurrent threadsUseCheckedTransfer?For each file: verify file sizestable before downloadDownload file directlyDownload file toLocalDirectoryDeleteOnSuccess?Delete file from remoteserverRemoteArchiveDirectoryset?Log successMove file toRemoteArchiveDirectoryMore files in queue?Log completion summarywith success/failure countsEnd

Processing Algorithm

The download process uses a multi-threaded approach to efficiently transfer multiple files:

  1. File Discovery: Connects to the remote server and searches the RemoteDirectory for files matching RemoteFileName (supports wildcards)
  2. Queue Creation: All matching files are added to a download queue
  3. Concurrent Download: Up to MaxDownloaders threads run in parallel, each pulling files from the queue
  4. Checked Transfer (optional): If UseCheckedTransfer = true, each file is checked multiple times to ensure its size remains constant (indicating the write is complete) before downloading
  5. Post-Transfer Actions: After successful download, files can be deleted or moved to an archive directory on the remote server
  6. Result Tracking: The task tracks succeeded and failed transfers, logging detailed results

Example Execution

Scenario: Downloading 100 CSV files from a vendor SFTP server with 10 concurrent downloaders:

Configuration:
- MaxDownloaders = 10
- RemoteFileName = "*.csv"
- RemoteDirectory = "/outbound/claims"
- UseCheckedTransfer = true

Execution:
1. Connect to SFTP server
2. Find 100 files matching "*.csv" in "/outbound/claims"
3. Add all 100 files to download queue
4. Start 10 downloader threads
5. Each thread:
   - Pull next file from queue
   - Check file size (wait if still changing)
   - Download file to LocalDirectory
   - Move file to RemoteArchiveDirectory
   - Process next file from queue
6. Complete when queue is empty
7. Log: "Completed. 100 Succeeded. 0 Failed."

Timeline: With 3KB files and stable network, approximately 10-30 seconds total

Usage Examples

Example 1: Basic SFTP download with archiving

// Download all CSV files from vendor and archive them on remote server
var task = new DownloadTask
{
    Host = "vendor.sftp.example.com",
    Port = 22,
    Username = "mdclarity_user",
    Password = "secure_password",
    Protocol = ProtocolSubset.Sftp,
    RemoteDirectory = "/outbound/data",
    RemoteFileName = "*.csv",
    LocalDirectory = @"C:\MDClarity\Downloads\Vendor",
    RemoteArchiveDirectory = "/archive/processed",
    // Files will be moved to /archive/processed after download
};

Example 2: Download specific file and delete after success

var task = new DownloadTask
{
    Host = "partner.ftp.example.com",
    Port = 21,
    Username = "integration_user",
    Password = "password123",
    Protocol = ProtocolSubset.Ftp,
    RemoteDirectory = "/reports",
    RemoteFileName = "daily_claims_[id].txt",  // Specific filename
    LocalDirectory = @"C:\MDClarity\Reports",
    DeleteOnSuccess = true,  // Remove from remote server after download
    ConnectionTimeoutInSeconds = 60
};

Example 3: High-volume download with checked transfer

// Download many files with parallel transfers, ensuring files are complete before downloading
var task = new DownloadTask
{
    Host = "data.sftp.example.com",
    Username = "mdclarity_prod",
    Password = "prod_password",
    Protocol = ProtocolSubset.Sftp,
    RemoteDirectory = "/exports/visits",
    RemoteFileName = "visit_*.dat",  // Pattern matching multiple files
    LocalDirectory = @"C:\MDClarity\Imports\Visits",
    MaxDownloaders = 15,  // Allow up to 15 concurrent downloads
    UseCheckedTransfer = true,  // Wait for files to finish writing before download
    RemoteArchiveDirectory = "/exports/archive"
};

Example 4: Download all files from a directory

var task = new DownloadTask
{
    Host = "backup.sftp.internal",
    Username = "backup_user",
    Password = "backup_pass",
    Protocol = ProtocolSubset.Sftp,
    RemoteDirectory = "/daily_exports",
    RemoteFileName = null,  // null or omitted = download all files in directory
    LocalDirectory = @"C:\MDClarity\Backups\Daily",
    MaxDownloaders = 5  // Conservative for potentially large files
};

Related Tasks Comparison

Task Use Case Direction Protocol Post-Transfer Actions
Download Retrieve files from remote servers Remote → Local FTP/SFTP Remote archive or delete
Upload Send files to remote servers Local → Remote FTP/SFTP Local archive or delete
LoadDataFile Import downloaded files into database Local file → Database N/A (local files) File archiving
AddFilesToQueue Queue files for processing Directory scan → Database queue Local or S3 None (creates queue entries)

Key Differences:


Performance Considerations

Network Impact

Optimization Tips

Scenario Recommendation Rationale
Many small files (100s of 3KB files) MaxDownloaders = 10-15 Parallel downloads maximize throughput for small files
Few large files (GBs) MaxDownloaders = 1-3 Avoid saturating bandwidth; focus on stable transfers
Unreliable network ConnectionTimeoutInSeconds = 300, UseCheckedTransfer = true Allow more time for connections; ensure complete files
Active file writes on remote UseCheckedTransfer = true Prevents downloading files that are still being written
High-volume daily imports Use RemoteArchiveDirectory instead of DeleteOnSuccess Preserves audit trail; allows reprocessing if needed