You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Automation运行WinSCP PowerShell模块崩溃重启求助

Azure Automation Runbook中WinSCP PowerShell模块异常问题

问题详情

我在Azure Automation Runbook中无法正常使用WinSCP PowerShell模块:

  • 最初通过库安装模块后,cmdlet无法正常显示
  • 按照其他线程建议在脚本顶部手动导入模块:
Import-Module -Name WinSCP
  • 但调用模块的代码出现静默失败,约30秒后整个Runbook自动重启

已开启详细日志,以下是相关代码及日志内容:

运行脚本

$SFTPSite = 'ftp IP address'
$SFTPDirectory = '/in/daily'
$LocalDirectory = $encryptedFilePath
$SessionLogFilePath = $encryptedFilePath + '\winscp.log'
$SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx"

$session = New-Object WinSCP.Session
$session.ExecutablePath = "C:\Modules\User\WinSCP\bin\WinSCP.exe"
$session.DebugLogPath = "$SessionLogFilePath"
$session.DebugLogLevel = "2"

$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.HostName = $SFTPSite
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.UserName = "unremoved"
$sessionOptions.SecurePrivateKeyPassphrase = $sftpPassPhrase
$sessionOptions.SshPrivateKeyPath = "$privateKeyFilePath"
$sessionOptions.SshHostKeyFingerprint = $SshHostKeyFingerprint

Write-Output "SFTP session created"

gc $SessionLogFilePath

try {
    $session.Open($sessionOptions) 

    Write-Output "SFTP session established"
        
    $directory = $session.ListDirectory($SFTPDirectory)
 
    foreach ($fileInfo in $directory.Files)
    {
        Write-Host ("$($fileInfo.Name) with size $($fileInfo.Length), " +
            "permissions $($fileInfo.FilePermissions) and " +
            "last modification at $($fileInfo.LastWriteTime)")
    }

    Write-Output "SFTP commands completed"
    $session.Dispose()
    Write-Output "SFTP session removed"

} catch {
    Write-Host "Error: $session.Output"
    gc $SessionLogFilePath
    $session.Dispose()
}

日志输出(未发现有效错误信息)

[2023-08-01 14:04:56.478] [0009] .NET Framework build
[2023-08-01 14:04:56.478] [0009] Executing assembly: WinSCPnet, Version=1.14.0.13736, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf
[2023-08-01 14:04:56.478] [0009] Executing assembly codebase: file:///C:/Modules/User/WinSCP/lib/net40/WinSCPnet.dll
[2023-08-01 14:04:56.478] [0009] Executing assembly location: C:\Modules\User\WinSCP\lib\net40\WinSCPnet.dll
[2023-08-01 14:04:56.478] [0009] Entry Assembly: Orchestrator.Sandbox, Version=7.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
[2023-08-01 14:04:56.478] [0009] Operating system: Microsoft Windows NT 6.2.9200.0
[2023-08-01 14:04:56.478] [0009] Bitness: 64-bit
[2023-08-01 14:04:56.478] [0009] Timezone: 00:00; Coordinated Universal Time
[2023-08-01 14:04:56.478] [0009] User: Administrator@CLIENT@CLIENT; Interactive: True
[2023-08-01 14:04:56.478] [0009] Runtime: 4.0.30319.42000
[2023-08-01 14:04:56.478] [0009] Console encoding: Input: Western European (Windows) (1252); Output: Western European (Windows) (1252)
[2023-08-01 14:04:56.478] [0009] Working directory: C:\Windows\System32
[2023-08-01 14:04:56.494] [0009] Assembly path: C:\Modules\User\WinSCP\lib\net40\WinSCPnet.dll
[2023-08-01 14:04:56.494] [0009] Assembly product version: 6.1.1.0
[2023-08-01 14:04:56.494] [0009] Entry assembly path: C:\Orchestrator\Orchestrator.Sandbox.exe

求帮忙解决这个问题!


内容的提问来源于stack exchange,提问作者MKRedacted

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 13:36:03