This code downloads the files from remote Unix server into Windows Server using WinSCP .NET assembly. But instead of copying all the logs files from the logs folder on the source Unix server into the destination Windows server, I just want it to copy logs for the last 30 day. The reason is I don't want it filling the C drive on the destination Window Server
param (
$localPath = "d:\Logs\OnlineLogs",
$remotePath = "/application/oracle",
$fileName = "int_access*.*"
)
try
{
# Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = ""
UserName = ""
Password = ""
SshHostKeyFingerprint = ""
}
$session = New-Object WinSCP.Session
try
{
$session.Open($sessionOptions)
$session.GetFiles(($remotePath + $fileName), ($localPath + $fileName)).Check()
}
finally
{
#Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch
{
Write-Host "Error: $($_.Exception.Message)"
exit 1
}