Re: How to upload a file with a specific keyword in a name for SFTP using WinSCP?
$session.PutFiles("E:\CMBPAID\*client*", "/NESAMSCARIMED/", $False, $transferOptions)
See https://winscp.net/eng/docs/library_session_putfiles
Before posting, please read how to report bug or request support effectively.
Bug reports without an attached log file are usually useless.
$session.PutFiles("E:\CMBPAID\*client*", "/NESAMSCARIMED/", $False, $transferOptions)
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "server"
UserName = "username"
Password = "password"
SshHostKeyFingerprint = "key"
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Upload files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult =
$session.PutFiles("E:\CMBPAID", "/NESAMSCARIMED", $False, $transferOptions)
# Throw on any error
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host "Upload of $($transfer.FileName) succeeded"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}