Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Exclude folder when downloading

I am taking over some work that was done by someone and I need to make some adjustments. However, I am not really good with PowerShell..any help is appreciated.

Add-Type -Path "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\Winscp\WinSCPnet.dll"
$Password = ConvertTo-SecureString 'XXXX' -AsPlainText -Force
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "XXXXX"
    UserName = "XXXX"
    Password = "XXXX"
    PortNumber = 11111
    SshHostKeyFingerprint = "XXXX"
    SshPrivateKeyPath = "C:\key\PrivateKey-UAT01.ppk"
    PrivateKeyPassphrase = "XXX"
$session = New-Object WinSCP.Session
$session.SessionLogPath = "C:\logs\winscpprod_pull.log"
# Connect
#Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.ResumeSupport.State =
$Source1 = "/OUTPUT/"
$Source2 = "/OUTPUT/1/"
$Source3 = "/OUTPUT/2/"
$Source4 = "/OUTPUT/3/"
$Source5 = "/OUTPUT/4/"
$Destination1 = "C:\Bla\1\"
$Destination2 = "C:\Bla\2\"
$Destination3 = "C:\Bla\3\"
$Destination4 = "C:\Bla\4\"
$Destination4 = "C:\Bla\5\"

The script has to copy files from the sftp server to a folder locally. However, it should do this only copying the files in the specific folder and exclude any subfolder of each given source location.

    $Source1 -filemask= /OUTPUT/1;/OUTPUT/2/" , $Destination1, $False, $transferOptions)

After reading some documentation this is how far I got. However, this doesn't work...I am probably doing something wrong..just don't know what.