Created
April 15, 2020 09:05
-
-
Save Jonatantwn/39c3ff9178c6711856da6cbdd26ca642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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