- martin
Post a reply
Topic review
- Idonthaveone
Exclude folder when downloading
Hi,
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.
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.
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.
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"
#PassPhrase
$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
$session.Open($sessionOptions)
#Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$transferOptions.ResumeSupport.State =
[WinSCP.TransferResumeSupportState]::Off
#VAR
$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.
$session.GetFiles(
$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.