Hi,
I have a script which works when $mask = "*.csv". It retrieves what it should. However, I would like to apply another mask, namely files modified within last 3 hours.
I've tried $mask = "*.csv | *>3H" which fails, and also $mask = "*>3H" which fails too.
If necessary, I can do without my file extention criteria.
I hope someone can help me implement the modifiedTime mask.
My script is:
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
#Add-Type -Path "WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::ftp
HostName = "ftp.host.com"
UserName = "testuser"
Password = "testpass"
}
$session = New-Object WinSCP.Session
try
{
# Connect
$session.Open($sessionOptions)
Write-Host "Session opened at $(Get-Date)."
$remotePath = "/folder/"
$localPath = "C:\data"
$mask = "*.csv"
$files = $session.EnumerateRemoteFiles(
$remotePath, $mask, [WinSCP.EnumerationOptions]::AllDirectories)
foreach ($fileInfo in $files)
{
Write-Host "Downloading $($fileInfo.FullName) ..."
$filePath = [WinSCP.RemotePath]::EscapeFileMask($fileInfo.FullName)
$session.GetFiles($filePath, $localPath + "\*").Check()
Write-Host "Download of $($fileInfo.FullName) succeeded"
}
}
finally
{
# Disconnect, clean up
$session.Dispose()
Write-Host "Session closed at $(Get-Date)."
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}