Repository navigation
Expand file tree
/
Copy pathExample.json
More file actions
192 lines (192 loc) · 12 KB
/
Copy pathExample.json
File metadata and controls
192 lines (192 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
{
"MaxConcurrent": {
"ActionsTotal": 4,
"PathsPerAction": 2,
"SftpSessionsPerServer": 8
},
"Tasks": [
{
"TaskName": "Step 1: Upload files",
"Sftp": {
"ComputerName": "sftp.xxx.be",
"Port": 22,
"Credential": {
"UserName": "SftpUserName",
"Password": "SftpPassword",
"PasswordKeyFile": null
}
},
"Option": {
"OverwriteFile": true,
"ExcludeZeroSizeFile": false,
"MatchFileNameRegex": ".*"
},
"Actions": [
{
"ComputerName": null,
"Paths": [
{
"Source": "\\SERVER\\C$",
"Destination": "sftp:/"
},
{
"Source": "\\SERVER\\C$\\reports",
"Destination": "sftp:/reports/"
}
]
}
]
},
{
"TaskName": "Step 2: Download files",
"Sftp": {
"ComputerName": "10.10.1.55",
"Port": 22,
"Credential": {
"UserName": "ENV:SFTP_USERNAME_ENVIRONMENT_VARIABLE",
"Password": "ENV:SFTP_PASSWORD_ENVIRONMENT_VARIABLE",
"PasswordKeyFile": null
}
},
"Option": {
"OverwriteFile": false,
"ExcludeZeroSizeFile": true,
"MatchFileNameRegex": "\\.csv$"
},
"Actions": [
{
"ComputerName": "SERVER1",
"Paths": [
{
"Source": "sftp:/",
"Destination": "C:\\Transfer"
},
{
"Source": "sftp:/reports/",
"Destination": "C:\\Transfer\\reports"
}
]
}
]
}
],
"PSSessionConfiguration": "PowerShell.7",
"Settings": {
"ScriptName": "Move file over SFTP",
"SendMail": {
"When": "OnError",
"From": "ENV:SCRIPT_ADMIN_EMAIL_ADDRESS",
"FromDisplayName": "",
"To": ["007@example.com"],
"Bcc": [],
"Subject": "",
"Body": "<p>The script does action xxx.</p>",
"Smtp": {
"ServerName": "ENV:SMTP_SERVER",
"Port": 587,
"ConnectionType": "StartTls",
"UserName": "ENV:SMTP_USERNAME",
"Password": "ENV:SMTP_PASSWORD"
},
"AssemblyPath": {
"MailKit": "C:\\Program Files\\PackageManagement\\NuGet\\Packages\\MailKit.4.11.0\\lib\\net8.0\\MailKit.dll",
"MimeKit": "C:\\Program Files\\PackageManagement\\NuGet\\Packages\\MimeKit.4.11.0\\lib\\net8.0\\MimeKit.dll"
}
},
"SaveLogFiles": {
"What": {
"SystemErrors": true,
"AllActions": true,
"OnlyActionErrors": true
},
"Where": {
"Folder": "..\\Logs",
"FileExtensions": [".csv", ".json", ".txt", ".xlsx"]
},
"DeleteLogsAfterDays": 30
},
"SaveInEventLog": {
"Save": false,
"LogName": "HCScripts"
}
},
"?": {
"MaxConcurrent": {
"ActionsTotal": "(Mandatory) Maximum quantity of 'Actions' to run at the same time across ALL computers. This is the overall concurrency budget. 'Tasks' are always run one after the other. Possible values: 1 - run one action at a time; 5 - run 5 actions at the same time; ...",
"PathsPerAction": "(Mandatory) Maximum quantity of 'Paths' to handle at the same time within a single action. Every path opens its own SFTP session, so this is the quantity of SFTP sessions opened by one action. Cannot be greater than 'SftpSessionsPerServer'.",
"SftpSessionsPerServer": "(Mandatory) Maximum quantity of SFTP sessions opened at the same time to ONE SFTP server. All actions within a task connect to the same SFTP server and tasks run one after the other, so this limit is enforced by running at most 'SftpSessionsPerServer / PathsPerAction' actions at the same time. Keep it below what the SFTP server accepts (for OpenSSH see 'MaxStartups' in sshd_config, other SFTP servers often limit the concurrent logins per user).",
"?": "The quantity of SFTP sessions to one SFTP server is 'ActionsTotal' x 'PathsPerAction', capped by 'SftpSessionsPerServer'. There is no setting per computer, because 'Tasks.Actions.ComputerName' is unique within a task and tasks run one after the other: a computer never handles more than one action at a time and never has more than one PowerShell session open."
},
"Tasks": [
{
"TaskName": "(Mandatory) Name of the task. Used in the email and log files.",
"Sftp": {
"ComputerName": "(Mandatory) The name of the computer where the SFTP server is running.",
"Port": "(Optional) The TCP port number used to connect to the SFTP server. Defaults to 22 if not specified.",
"Credential": {
"UserName": "(Mandatory) SFTP user name. Supports environment variables (e.g., 'ENV:SFTP_USERNAME').",
"Password": "(Mandatory 'Password' or 'PasswordKeyFile') SFTP password. Supports environment variables (e.g., 'ENV:SFTP_PASSWORD').",
"PasswordKeyFile": "(Mandatory 'Password' or 'PasswordKeyFile') Path to the SFTP password key file used to authenticate to the SFTP server. This is an SSH private key file in the OpenSSH format. Supports environment variables (e.g., 'ENV:SFTP_PASSWORD_KEY_FILE')."
}
},
"Option": {
"OverwriteFile": "(Mandatory) Specifies whether to overwrite duplicate files in the destination folder. Possible values: true - Overwrite duplicate files; false - Do not overwrite duplicate files and log an error.",
"ExcludeZeroSizeFile": "(Mandatory) Whether to move files with a size of 0 bytes. Possible values: true or false.",
"MatchFileNameRegex": "(Mandatory) A regular expression to match file names. Possible values: '.*' - Process all files; '\\.xlsx$' - Process only Excel files; 'Report_[0-9]{8}\\.xlsx$' - Process only files with names starting with 'Report_' and ending with '.xlsx' followed by 8 digits; ..."
},
"Actions": [
{
"ComputerName": "(Optional) The name of the computer where the SFTP commands will be run. Ensure the 'Posh-SSH' PowerShell module is installed on this machine. Possible values: 'SERVER1' - A remote server name; 'localhost' or NULL - The local system.",
"Paths": [
{
"Source": "(Mandatory) The path to the source folder. Possible values: 'sftp:\\path' - A string that starts with 'sftp:\\' representing a folder on the SFTP server defined in 'Sftp.ComputerName'; 'c:\\path' - A string representing a folder on the file system in 'Actions.ComputerName'.",
"Destination": "(Mandatory) The path to the destination folder. Possible values: 'sftp:\\path' - A string that starts with 'sftp:\\' representing a folder on the SFTP server defined in 'Sftp.ComputerName'; 'c:\\path' - A string representing a folder on the file system in 'Actions.ComputerName'."
}
]
}
]
}
],
"PSSessionConfiguration": "(Optional) The PowerShell version of the remote endpoint. This value corresponds to the output of the Get-PSSessionConfiguration cmdlet. The minimum supported version is 'PowerShell.7'. Defaults to 'PowerShell.7' if not specified.",
"Settings": {
"ScriptName": "(Mandatory) Name of the script, used in the log files and in the event logs.",
"SendMail": {
"When": "(Mandatory) Specifies when to send an email notification. Possible values: 'OnError' - Send email only when a system error or an action error occurs; 'OnErrorOrAction' - Send email when the script performed actions or when errors occurred; 'Always' - Send email when the script is finished, regardless of success or failure; 'Never' - Do not send email.",
"From": "(Mandatory) The sender's email address. Supports environment variables (e.g., 'ENV:MAIL_FROM_ADDRESS').",
"FromDisplayName": "(Optional) The display name to show for the sender. Email clients may display this differently. It is most likely to be shown if the sender's email address is not recognized (e.g., not in the address book). Supports environment variables (e.g., 'ENV:MAIL_FROM_DISPLAY_NAME').",
"To": "(Mandatory 'To' or 'Bcc') An array of recipient email addresses. The script will send an email to all addresses in the array.",
"Bcc": "(Mandatory 'To' or 'Bcc') An array of BCC email addresses.",
"Subject": "(Optional) The subject line of the email. Default value: 'N actions, N errors'",
"Body": "(Optional) The HTML body of the email. Default value: A summary table with action and error count.",
"Smtp": {
"ServerName": "(Mandatory) The hostname or IP address of the SMTP server. Supports environment variables (e.g., 'ENV:SMTP_SERVER').",
"Port": "(Mandatory) The port number of the SMTP server. Possible values: 25, 465, 587, 2525. Supports environment variables (e.g., 'ENV:SMTP_PORT').",
"ConnectionType": "(Optional) The connection type for the SMTP server. Possible values: 'None' - No encryption; 'Auto' - Attempt TLS, fall back to unencrypted; 'SslOnConnect' - Use SSL from the beginning; 'StartTls' - Start with unencrypted, then upgrade to TLS; 'StartTlsWhenAvailable' - Start with unencrypted, upgrade to TLS if supported. Default value: 'None'. Supports environment variables (e.g., 'ENV:SMTP_CONNECTION_TYPE').",
"UserName": "(Optional) The username for authenticating with the SMTP server. If undefined or NULL, no authentication is attempted. Supports environment variables (e.g., 'ENV:SMTP_USERNAME').",
"Password": "(Optional) The password for authenticating with the SMTP server. If undefined or NULL, no authentication is attempted. Supports environment variables (e.g., 'ENV:SMTP_PASSWORD')."
},
"AssemblyPath": {
"?": "To use email functionality, install the following packages: 'Install-Package -Name 'MailKit' -Source 'https://www.nuget.org/api/v2' -Scope 'AllUsers' -SkipDependencies' and 'Install-Package -Name 'MimeKit' -Source 'https://www.nuget.org/api/v2' -Scope 'AllUsers' -SkipDependencies'",
"MailKit": "(Mandatory) Path to the MailKit.dll assembly. Supports environment variables (e.g., 'ENV:MAILKIT_ASSEMBLY').",
"MimeKit": "(Mandatory) Path to the MimeKit.dll assembly. Supports environment variables (e.g., 'ENV:MIMEKIT_ASSEMBLY')."
}
},
"SaveLogFiles": {
"What": {
"SystemErrors": "(Mandatory) Whether to log execution errors, incorrect input file errors, etc. Possible values: true or false.",
"AllActions": "(Mandatory) Whether to log all actions performed by the script, including errors. Possible values: true or false.",
"OnlyActionErrors": "(Mandatory) Whether to log only actions that failed. Possible values: true or false."
},
"Where": {
"Folder": "(Mandatory) The path to the folder where log files will be created. Value '..\\Logs': Path relative to the script. Value 'C:\\MyApp\\Logs': An absolute path. If not specified or NULL, no log files will be created. Supports environment variables (e.g., 'ENV:LOG_FOLDER').",
"FileExtensions": "(Mandatory) An array of file extensions for the log files (e.g., ['.csv'], ['.json'], ['.txt'], ['.xlsx']). Multiple values are supported. Ignored when Folder is NULL. To use '.xlsx', install the following PowerShell modules 'Install-Module ImportExcel'."
},
"DeleteLogsAfterDays": "(Optional) The number of days to keep log files. Log files older than this value (based on their last write time) will be removed from the log folder specified in 'SaveLogFiles.Where.Folder'. If not specified or 0, logs will be kept indefinitely. CAUTION: Ensure the 'SaveLogFiles.Where.Folder' is specifically designated for log files to avoid unintended deletion of other files."
},
"SaveInEventLog": {
"Save": "(Mandatory) Whether to log messages to the Windows event log. Possible values: true or false.",
"LogName": "(Mandatory) The name of the event log to write to (e.g., 'Application', 'System', or a custom log name like 'Scripts'). Supports environment variables (e.g., 'ENV:EVENT_LOG_NAME')."
}
}
}
}