Post a reply

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)


Topic review




another attachment

Session Log

It actually doesn't generate a session log. It looks like it just creates the folder then stops but I do not get an error in task scheduler.

Re: PowerShell script not downloading data but creates folder when in Task Scheduler

Do you get any error message? 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.

Btw, it should be $localPath, not $remotePath

PowerShell script not downloading data but creates folder when in Task Scheduler

I am trying to have files downloaded daily from SFTP to local and have it create a folder first then add the files to that folder. It works when not in Task Scheduler but task scheduler only creates the folder. Here is the code that I am using below.
$date = ((Get-Date).AddDays(-1)).ToString("MMddyyyy")
New-Item -Path "C:\Data" -Name $date -ItemType Directory
# Load WinSCP .NET assembly
Add-Type -Path "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
    # Connect
    # Transfer files
    $remotePath = "C:\Data\$date\*"
    $session.GetFiles("/datafeed/*", $remotePath, $True).Check()