Add local archive and rename-after-upload options

This commit is contained in:
2026-04-16 21:36:35 -05:00
parent 6a451044dd
commit 8505e75757
2 changed files with 145 additions and 13 deletions
+34 -3
View File
@@ -42,10 +42,13 @@ The script auto-searches these locations in order:
| `-CredentialFile` | No | — | Path to saved credential XML (see below) |
| `-KeyFilePath` | No | — | Path to SSH private key (`.ppk`) |
| `-SshHostKeyFingerprint` | No | — | SSH host key fingerprint for verification |
| `-RenamePattern` | No | — | Regex pattern to match in filename for renaming before upload |
| `-RenamePattern` | No | — | Regex pattern to match in filename for renaming on the **remote** side before upload |
| `-RenameReplacement` | No | — | Replacement string for `-RenamePattern` (supports capture groups like `$1`) |
| `-ArchivePath` | No | — | Move successfully uploaded files to this local folder (created if missing). Cannot combine with `-DeleteAfterTransfer` |
| `-LocalRenamePattern` | No | — | Regex pattern to rename the **local** file after upload (in place, or into `-ArchivePath`) |
| `-LocalRenameReplacement` | No | — | Replacement string for `-LocalRenamePattern` (supports capture groups like `$1`) |
| `-Recurse` | No | `false` | Scan subdirectories |
| `-DeleteAfterTransfer` | No | `false` | Delete local files after successful upload |
| `-DeleteAfterTransfer` | No | `false` | Delete local files after successful upload. Cannot combine with `-ArchivePath` |
| `-DryRun` | No | `false` | Preview transfers without uploading |
| `-LogFile` | No | — | Path to log file (logs to console if omitted) |
| `-WinScpDllPath` | No | — | Explicit path to `WinSCPnet.dll` |
@@ -127,7 +130,35 @@ The `-FileFilter` parameter uses PowerShell regex (case-insensitive by default).
-Recurse -FileFilter '\.pdf$'
```
## Renaming Files Before Upload
## Local Archive & Rename After Upload
After a successful upload you can archive or rename the local source file. These are mutually exclusive with `-DeleteAfterTransfer`.
### Archive to a folder
```powershell
.\Send-FilesToSftp.ps1 -LocalPath "C:\exports" -RemotePath "/incoming" `
-HostName "sftp.example.com" -UserName "uploader" `
-ArchivePath "C:\exports\sent"
```
### Archive and rename while archiving (e.g. add `_sent` before extension)
```powershell
.\Send-FilesToSftp.ps1 -LocalPath "C:\exports" -RemotePath "/incoming" `
-HostName "sftp.example.com" -UserName "uploader" `
-ArchivePath "C:\exports\sent" `
-LocalRenamePattern '^(.+?)(\.[^.]+)$' -LocalRenameReplacement '${1}_sent${2}'
```
### Rename local file in place (no archive, no delete)
```powershell
.\Send-FilesToSftp.ps1 -LocalPath "C:\exports" -RemotePath "/incoming" `
-HostName "sftp.example.com" -UserName "uploader" `
-LocalRenamePattern '^' -LocalRenameReplacement 'done_'
```
> `-LocalRenamePattern`/`-LocalRenameReplacement` only rename the local file — the remote name is controlled by `-RenamePattern`/`-RenameReplacement`. You can use both together.
## Renaming Files on the Remote Side
Use `-RenamePattern` (regex) and `-RenameReplacement` together to rename files on the remote side without touching the local files.