Already fixed :-)!
Added following variable:
$wildcard = "*.csv"
Write-Host "Looking for new files..." $files = $session.EnumerateRemoteFiles( $remotePath, $wildcard, [WinSCP.EnumerationOptions]::None)
Adjusting the following line helped a bit, but the FileMask isn't working.
$session.GetFiles($source, $localFilePath, $False, $transferOptions).Check()
Filemask looks like this now:
$transferOptions = New-Object WinSCP.TransferOptions $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $transferOptions.FileMask = "*.csv; /PATH1/ | */"
What I'm trying to do is:
Download files from a remote sftp server to local, so the situation is as follow:
local path: c:\path
remote path: /FILES1/ (do not recurse, only include this directory, not subdirectory's)
So what I did, I've used the example script from Martin and adjusted it a bit:
$transferOptions = New-Object WinSCP.TransferOptions $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::On $transferOptions.FileMask = "*.csv | */"
I am running the script with the following command:
powershell.exe -File C:\path\DownloadNewFilesAno.ps1 -sessionUrl "sftp://username:email@example.com/" -localPath "C:\path" -remotePath "/FILES1" -listPath "C:\path\downloaded.txt"
The complete script is added. Please, can someone help me out what I'm doing wrong? Do I need to call $transferoptions somewhere else?