Trying to create a Powershell script that pulls new files
Hello,
I've been trying to create a PowerShell script that transfers all files created/modified within the past week, and places them in a folder. According to PowerShell, the script runs and finishes, no errors and PowerShell doesn't close. I came up with the following, based on a couple stackoverflow topics and reading stuff here.
As I said, powershell stopped giving me errors, so didn't have anything to go off of on that front. I've tried reading some of the articles here, but being extremely new to not only this but scripting in general, I haven't been able to figure out what's wrong. I've tried some blind experiments (re-arranging stuff, using .Put instead of .Get, '<' instead of '>') but nothing happens. My guess is I'm using $transferOptions wrong, but I can't figure out the how/why. Any help would be appreciated. Thank you.
I've been trying to create a PowerShell script that transfers all files created/modified within the past week, and places them in a folder. According to PowerShell, the script runs and finishes, no errors and PowerShell doesn't close. I came up with the following, based on a couple stackoverflow topics and reading stuff here.
# Load WinSCP .NET assembly Add-Type -Path "C:\FilePath\WinSCP\WinSCPnet.dll" # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Ftp HostName = "BlahBlah" UserName = "BlahBlah" Password = "BlahBlah" } $session = New-Object WinSCP.Session try { # Connect $session.Open($sessionOptions) # Transfer files $remotePath = "\\LocalFilePath\*" $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.FileMask = "*>=7D" $session.GetFiles("/FTPFilePath/*.csv", $remotePath, $False, $transferOptions).Check() } finally { $session.Dispose() }