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

Advertisement

caghassi
Joined:
Posts:
4

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
 
try
{
    # Connect
    $session.Open($sessionOptions)
    
    # Transfer files
    $remotePath = "C:\Data\$date\*"
    $session.GetFiles("/datafeed/*", $remotePath, $True).Check()
}
finally
{
}

Reply with quote

Advertisement

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

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

Reply with quote

caghassi
Joined:
Posts:
4

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.
  • Capture 3.PNG (10 KB, Private file)
  • Capture 2.PNG (28.36 KB, Private file)
  • Capture 3.PNG (10 KB, Private file)

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum