Need to download ALL files from the current date date
I am having a problem downloading ALL files in a directory with the current date. I have the script where it will only download the latest file. I need it to download ALL files from the current date. There is 199 small files uploaded daily.
Here is my script:
I also have this one which I tried to modify for use with multiple files.
Here is my script:
param ( $localPath = "C:\HPHC TEST\*", $remotePath = "/users/" ) try { # Load WinSCP .NET assembly Add-Type -Path "WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "test.com" UserName = "test" Password = "testing" SshHostKeyFingerprint = "ssh-rsa 1024 test" } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Get list of files in the directory $directoryInfo = $session.ListDirectory($remotePath) # Select the most recent file $latest = $directoryInfo.Files | Where-Object { -Not $_.IsDirectory } | Sort-Object LastWriteTime -Descending | Select-Object -First 1 # Any file at all? if ($latest -eq $Null) { Write-Host "No file found" exit 1 } # Download the selected file $session.GetFiles( [WinSCP.RemotePath]::EscapeFileMask($latest.FullName), $localPath).Check() } finally { # Disconnect, clean up $session.Dispose() } exit 0 } catch { Write-Host "Error: $($_.Exception.Message)" exit 1 }
# Load WinSCP .NET assembly Add-Type -Path "WinSCPnet.dll" # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "test.com" UserName = "test" Password = "testing" SshHostKeyFingerprint = "ssh-rsa 1024 test" } $sessionOptions.AddRawSettings("SendBuf", "0") $sessionOptions.AddRawSettings("SshSimple", "0") $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Transfer files $session.GetFiles("/users/%TIMESTAMP#ddmmyyyy%.txt", "C:\HPHC TEST\*").Check() } finally { $session.Dispose() }