- martin
Post a reply
Topic review
- martin
Re: PowerShell script not downloading data but creates folder when in Task Scheduler
Once again, do you get any error in the PowerShell? What does the Powershell output? What did you try to debug the problem? Did you use
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript
Start-Transcript
?
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript
- caghassi
bump
bump
- caghassi
another attachment
- caghassi
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.
- martin
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).
Btw, it should be
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
- caghassi
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
{
}