Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$FileList = (Get-ChildItem 'C:\Users\Dern\Desktop\Searchtarget\searchtargetlist.txt').fullname
foreach ($FileName in $FileList) {
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Users\Dern\Desktop\WINSCP PS\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::ftp
HostName = "XXX.unoeuro.com"
UserName = "wktXXX"
Password = "X252135"
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
# Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferResult =
$session.GetFiles("$FileName", "C:\Users\Dern\Desktop\WINSCP PS DOWNLOAD\", $False, $transferOptions)
# Throw on any error deactivate
$transferResult.Check()
# Print results
foreach ($transfer in $transferResult.Transfers)
{
Write-Host "Download of $($transfer.FileName) succeeded"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.