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:
- Uploading files via HTTP/HTTPS (use a web upload client instead)
- Accessing cloud storage like S3 or Azure Blob Storage (use cloud-specific clients)
- Files need to stay on local filesystem (no upload needed)
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
Processing Algorithm
The upload process builds a queue of files and processes them sequentially:
File Queue Building:
- If
LocalFileNameis specified, adds the single file path to the queue - If
LocalFileNameis null or empty, adds all files fromLocalDirectoryto the queue - Only existing files are added to the queue
- If
Session Establishment: Opens a single WinSCP session for all uploads
Remote Directory Creation: If
RemoteDirectorydoesn't exist on the server, creates itSequential Upload: Processes each file from the queue:
- Uploads file to
RemoteDirectorywith same filename - Tracks success or failure for each file
- On success, executes post-transfer actions in order
- Uploads file to
Post-Transfer Actions (executed only on successful upload):
- LocalArchive (if
LocalArchiveDirectoryset): Copies file to archive directory with timestamped filename - Delete (if
DeleteOnSuccess = true): Deletes original file fromLocalDirectory
- LocalArchive (if
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:
- Upload vs Download: Upload sends files from local to remote; Download retrieves files from remote to local
- Upload vs LoadDataFile: Upload transfers files to remote servers; LoadDataFile imports local files into database tables
- Upload vs AddFilesToQueue: Upload transfers files to remote locations; AddFilesToQueue creates processing queue entries for existing files
Performance Considerations
Network Impact
- Bandwidth: Uploads are limited by network bandwidth and server capacity
- Connection Management: Uses a single WinSCP session for all files in the queue
- Connection Timeout:
ConnectionTimeoutInSecondsshould be increased for slow or unreliable connections - Sequential Processing: Files are uploaded one at a time (no concurrent upload threads like DownloadTask)
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 |