Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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.
BlaaargPirate

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.