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

MDClarity · task primitive

Upload

Overview

UploadTask uploads files from local directories to remote FTP or SFTP servers. It supports uploading a specific file or all files in a directory, with optional post-transfer actions including local archiving and deletion after successful upload.

Use this task when: You need to send data files to 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 where files will be uploaded
LocalDirectory string Yes - Local directory containing the file(s) to upload
LocalFileName string No null Specific filename to upload. If null or empty, all files in LocalDirectory are uploaded
LocalArchiveDirectory string No null If set, successfully uploaded files are copied to this local directory before optional deletion
DeleteOnSuccess bool No false Delete files from local directory after successful upload

Execution Flow

YesNoYesNoNoYesNoYesYesNoYesNoYesNoStart UploadTaskCreate UploadClient andUploadParamsValidate parametersValidation errors?ThrowValidationFailedExceptionCreate missing localdirectories ifLocalArchiveDirectory setLocalFileName specified?Build upload queue withsingle fileBuild upload queue with allfiles in LocalDirectoryCreate session with servercredentialsRemote directory exists?Create remote directoryProcess upload queueFor each file in queueUpload file toRemoteDirectoryUpload successful?Add to FailedTransfers listand log errorLocalArchiveDirectory set?More files in queue?Copy file toLocalArchiveDirectory withtimestampDeleteOnSuccess?Delete file fromLocalDirectoryAdd to SucceededTransferslistLog completion summarywith success/failure countsEnd

Processing Algorithm

The upload process builds a queue of files and processes them sequentially:

  1. File Queue Building:

    • If LocalFileName is specified, adds the single file path to the queue
    • If LocalFileName is null or empty, adds all files from LocalDirectory to the queue
    • Only existing files are added to the queue
  2. Session Establishment: Opens a single WinSCP session for all uploads

  3. Remote Directory Creation: If RemoteDirectory doesn't exist on the server, creates it

  4. Sequential Upload: Processes each file from the queue:

    • Uploads file to RemoteDirectory with same filename
    • Tracks success or failure for each file
    • On success, executes post-transfer actions in order
  5. Post-Transfer Actions (executed only on successful upload):

    • LocalArchive (if LocalArchiveDirectory set): Copies file to archive directory with timestamped filename
    • Delete (if DeleteOnSuccess = true): Deletes original file from LocalDirectory
  6. Result Summary: Logs count of succeeded and failed transfers

Example Execution

Scenario: Uploading 5 export files to vendor SFTP with local archiving:

Configuration:
- LocalDirectory = "C:\MDClarity\Exports\Claims"
- LocalFileName = null  (upload all files)
- RemoteDirectory = "/inbound/claims"
- LocalArchiveDirectory = "C:\MDClarity\Archive\Claims"
- DeleteOnSuccess = true

Files in C:\MDClarity\Exports\Claims:
- claims_[id]_001.csv
- claims_[id]_002.csv
- claims_[id]_003.csv
- claims_[id]_004.csv
- claims_[id]_005.csv

Execution:
1. Connect to SFTP server
2. Add all 5 CSV files to upload queue
3. Ensure /inbound/claims exists on remote
4. For each file:
   - Upload to /inbound/claims/claims_[id]_001.csv
   - Copy to C:\MDClarity\Archive\Claims\claims_[id]_001_[id]_143022.csv
   - Delete from C:\MDClarity\Exports\Claims
5. Log: "Completed. 5 Succeeded. 0 Failed."

Result:
- Remote: 5 files in /inbound/claims/
- Local: 0 files in Exports, 5 timestamped files in Archive

Usage Examples

Example 1: Basic SFTP upload with local archiving

// Upload all export files to vendor and archive them locally
var task = new UploadTask
{
    Host = "vendor.sftp.example.com",
    Port = 22,
    Username = "mdclarity_sender",
    Password = "secure_password",
    Protocol = ProtocolSubset.Sftp,
    LocalDirectory = @"C:\MDClarity\Exports\Vendor",
    // LocalFileName not set = upload all files in directory
    RemoteDirectory = "/inbound/mdclarity",
    LocalArchiveDirectory = @"C:\MDClarity\Archive\Vendor",
    // Files will be copied to archive before optional deletion
};

Example 2: Upload specific file and delete after success

var task = new UploadTask
{
    Host = "partner.ftp.example.com",
    Port = 21,
    Username = "integration_user",
    Password = "password123",
    Protocol = ProtocolSubset.Ftp,
    LocalDirectory = @"C:\MDClarity\Reports",
    LocalFileName = "daily_summary_[id].txt",  // Upload only this file
    RemoteDirectory = "/incoming/reports",
    DeleteOnSuccess = true,  // Remove from local after successful upload
    ConnectionTimeoutInSeconds = 60
};

Example 3: Upload with archiving and deletion

// Upload files, archive locally, then clean up originals
var task = new UploadTask
{
    Host = "data.sftp.example.com",
    Username = "mdclarity_prod",
    Password = "prod_password",
    Protocol = ProtocolSubset.Sftp,
    LocalDirectory = @"C:\MDClarity\Exports\Claims",
    LocalFileName = "claims_export.csv",
    RemoteDirectory = "/uploads/claims",
    LocalArchiveDirectory = @"C:\MDClarity\Archive\Claims",
    DeleteOnSuccess = true,
    // File will be: uploaded -> archived -> deleted from original location
};

Example 4: Bulk upload without cleanup

// Upload all files but keep local copies (no archiving or deletion)
var task = new UploadTask
{
    Host = "backup.sftp.internal",
    Username = "backup_user",
    Password = "backup_pass",
    Protocol = ProtocolSubset.Sftp,
    LocalDirectory = @"C:\MDClarity\Backups\Daily",
    RemoteDirectory = "/backups/mdclarity/daily",
    // No LocalArchiveDirectory or DeleteOnSuccess = files remain in original location
};

Related Tasks Comparison

Task Use Case Direction Protocol Post-Transfer Actions
Upload Send files to remote servers Local → Remote FTP/SFTP Local archive or delete
Download Retrieve files from remote servers Remote → Local FTP/SFTP Remote archive or delete
LoadDataFile Import 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 KB files) Group uploads into batches; run multiple UploadTask instances for different directories Sequential processing can be slow for many files
Few large files (GBs) ConnectionTimeoutInSeconds = 300+ Large files need more time to transfer completely
Unreliable network ConnectionTimeoutInSeconds = 300, use LocalArchiveDirectory without DeleteOnSuccess Preserve files locally until verified on remote
Regulatory compliance Always use LocalArchiveDirectory Maintains local audit trail of sent files
Disk space management Set DeleteOnSuccess = true after archiving Prevents accumulation of sent files