WinSCP.Session.SessionLogPath error with UNC path, invoking process has permission

Advertisement

sgcaveney
Guest

WinSCP.Session.SessionLogPath error with UNC path, invoking process has permission

Scenario: PowerShell 7 host, WinSCP.exe 6.5.7.16562, WinSCPnet.dll 1.16.1.16562

Add-Type -Path 'X:\path\to\WinSCP\netstandard2.0\WinSCPnet.dll'
 
$opts = [WinSCP.SessionOptions]::new()
$opts.Protocol                    = 'Sftp'
$opts.HostName                    = $sftp_hostname
$opts.SshHostKeyFingerprint       = $sftp_fingerprint
$opts.UserName                    = $sftp_username
$opts.SshPrivateKeyPath           = $sftp_privkey
$opts.SecurePrivateKeyPassphrase  = $sftp_passphrase
 
$sess = [WinSCP.Session]::new()
$sess.SessionLogPath = $sftp_sesslog
 
$txopts = [WinSCP.TransferOptions]::new()
$txopts.TransferMode  = 'Binary'
$txopts.OverwriteMode = 'Overwrite'
 
$sess.open($opts)
Invoking code in interactive session works perfectly as expected, but when running in an automated context the call to .Open($opts) throws:
Exception calling "Open" with "1" argument(s): "Error occurred during logging. It's been turned off.
Can't open log file '\\fqdn.smb.host\Logs\Prod\SFTP\2026\11\2026-11-16_JobName_WinSCP.log'.
System Error. Code: 5.
Access is denied"
The automated process has full permissions to that UNC path as a separate log file is being written in that folder, so I am at a loss as to why WinSCP logging did not complete. Are UNC paths not acceptable in this usage?

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum