Trying to create a Powershell script that pulls new files

Advertisement

BlaaargPirate
Joined:
Posts:
1

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.
# 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()
}
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.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: Trying to create a Powershell script that pulls new files

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Advertisement

You can post new topics in this forum