Re: Need Assistance Uploading All files within a Directory (while excluding subfolders)
That was it. Thanks!
$transferResult =
$session.PutFiles($localPath, $remotePath, $False, $transferOptions)
param (
$localPath = "C:\Data\SFTP\xxx\to_xxx\*",
$remotePath = "/toxxx/*",
$backupPath = "C:\Data\SFTP\xxx\to_xxx\Transfered"
)
# ...
# Set up transfer options
$transferOptions = New-Object WinSCP.TransferOptions -Property @{
FileMask = "*.* | */"
}
$transferOptions.AddRawSettings("IgnorePermErrors", "1")
# Upload files, collect results
$transferResult = $session.PutFiles($localPath, $remotePath, $transferOptions )
# Iterate over every transfer
foreach ($transfer in $transferResult.Transfers)
{
# Success or error?
if ($transfer.Error -eq $Null)
{
Write-Host "Upload of $($transfer.FileName) succeeded, moving to backup"
# Upload succeeded, move source file to backup
Move-Item $transfer.FileName $backupPath
}
else
{
Write-Host "Upload of $($transfer.FileName) failed: $($transfer.Error.Message)"
}
}