Skip to main content
Version: Next

FileDownloaderActivity - File Synchronization

Overview​

FileDownloaderActivity is a file synchronization node used to synchronize files from SMB shared folders to local directories. This node supports authentication for remote shared folders, file matching filtering, synchronization mode selection, and source file deletion.

Basic Information​

PropertyValue
Display NameFile Synchronization
Class NameFileDownloaderActivity
NamespaceCMS.Plugin.FlowManagement.Domain.FlowBusiness.Activitys
Base ClassActionActivity
CategoryFile Operations
VisibilityVisible (Visible = true)
Sort20

Configuration Description​

SMB Configuration​

Property NameDisplay NameTypeDefaultDescription
SoruceDirectoryPathSource DirectorystringnullRemote shared folder path, directory to sync
UserNameUsernamestringnullSMB share access username
PasswordPasswordstringnullSMB share access password
SearchPatternMatch Patternstring"*.csv"File match pattern, supports wildcards
SearchOptionSearch OptionSearchOptionTopDirectoryOnlySearch scope: Top directory only or include subdirectories
TargetDirectoryPathTarget Directorystring"FileDownloaderTempFiles"Local target directory, supports absolute or relative paths
DeleteSourceFileDelete Source FilebooltrueWhether to delete source files after synchronization
SynchronousModeFile Sync ModeFileSynchronousModeSkipHandling method when target file exists
SavePathsContextProcess ContextstringnullContext variable name to store synchronized file paths collection

Search Option (SearchOption)​

Enum ValueDescription
TopDirectoryOnlySearch only the top directory
AllDirectoriesSearch all subdirectories

File Sync Mode (FileSynchronousMode)​

Enum ValueDescription
SkipSkip existing files
RenameRename new files (add sequence suffix)

Process Context​

Output Variables​

Variable NameTypeDescription
{SavePathsContext}List<string>Collection of synchronized target file paths (Variable name specified by configuration)

Business Logic​

Execution Flow​

┌─────────────────────────────────────────────────────────────┐
│ FileDownloaderActivity │
├─────────────────────────────────────────────────────────────┤
│ 1. Determine Source Directory Type │
│ ├─ Local path (e.g. C:\...) → Direct access │
│ └─ Network path (e.g. \\server\...) → Establish SMB conn│
├─────────────────────────────────────────────────────────────┤
│ 2. Establish SMB Connection (if needed) │
│ └─ Use net use command to connect share │
├─────────────────────────────────────────────────────────────┤
│ 3. Scan Source Directory │
│ └─ Find files based on SearchPattern and SearchOption │
├─────────────────────────────────────────────────────────────┤
│ 4. Sync Files │
│ ├─ Check if target file exists │
│ ├─ Handle conflict based on SynchronousMode │
│ ├─ Copy file to target directory │
│ └─ Delete source file (if configured) │
├─────────────────────────────────────────────────────────────┤
│ 5. Output Result │
│ └─ Store synced file paths to process context │
└─────────────────────────────────────────────────────────────┘

Path Handling​

  • Local Path Check: Checks if the second character of the path is : (e.g., C:\).
  • Relative Path Conversion: Non-absolute paths are automatically converted to absolute paths relative to the application directory.
  • Auto Create Directory: Automatically creates the target directory if it does not exist.

File Conflict Handling​

ModeHandling Method
SkipSkip synchronization, keep original file
RenameAdd sequence number to filename, e.g., file-1.csv, file-2.csv

Usage Examples​

Basic Configuration​

{
"Name": "Sync CSV Files",
"Type": "FileDownloaderActivity",
"SoruceDirectoryPath": "\\\\192.168.1.100\\share\\data",
"UserName": "admin",
"Password": "password123",
"SearchPattern": "*.csv",
"TargetDirectoryPath": "SyncFiles",
"DeleteSourceFile": true,
"SynchronousMode": "Skip",
"SavePathsContext": "SyncedFiles"
}

Sync All Subdirectories​

{
"Name": "Sync All Files",
"Type": "FileDownloaderActivity",
"SoruceDirectoryPath": "\\\\fileserver\\backup",
"UserName": "backup_user",
"Password": "backup_pwd",
"SearchPattern": "*.*",
"SearchOption": "AllDirectories",
"TargetDirectoryPath": "D:\\LocalBackup",
"DeleteSourceFile": false,
"SynchronousMode": "Rename"
}

Local Directory Sync​

{
"Name": "Local File Sync",
"Type": "FileDownloaderActivity",
"SoruceDirectoryPath": "D:\\SourceData",
"SearchPattern": "*.xml",
"TargetDirectoryPath": "ProcessedData",
"DeleteSourceFile": true,
"SavePathsContext": "ProcessedFiles"
}

Coordination with Subsequent Processing​

┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│FileDownloaderActivity│──▶│ CsvReadActivity │──▶│ DataFilterActivity│
│ Sync CSV Files │ │ Read Synced Files│ │ Process Data │
│ SavePathsContext: │ │ │ │ │
│ "SyncedFiles" │ │ │ │ │
└──────────────────┘ └──────────────────┘ └──────────────────┘

Notes​

  1. Network Access Permissions: Ensure the running account has permission to access the SMB share.
  2. Firewall Settings: Ensure SMB port (445) is not blocked by the firewall.
  3. Credential Security:
    • Avoid storing passwords in plain text in configuration.
    • Recommended to use configuration encryption or credential management.
  4. Disk Space: Ensure the target directory has sufficient disk space.
  5. File Locking:
    • Copy may fail if the source file is in use.
    • If deleting the source file fails due to being in use, an exception is recorded but the process is not interrupted.
  6. Path Format:
    • Network paths use UNC format: \\server\share\folder
    • Local paths use standard format: C:\folder or relative paths.
  7. Performance Considerations:
    • Pay attention to network bandwidth when syncing large numbers of files.
    • Recommended to perform bulk synchronization during off-peak hours.

Error Handling​

Error ScenarioHandling Method
SMB Connection FailedThrow exception, record error info
File Copy FailedRecord exception, continue processing next file
Source File Delete FailedRecord exception, does not affect sync result
Target Directory Create FailedThrow exception

Last updated: 2025-11-28