简体   繁体   English

使用 WinSCP .NET 的方法未找到异常 (EventWaitHandle..ctor)

[英]Method not found exception (EventWaitHandle..ctor) using WinSCP .NET

I am trying to connect to SFTP server using PowerShell, and using WinSCP .NET assembly.我正在尝试使用 PowerShell 并使用 WinSCP .NET 程序集连接到 SFTP 服务器。

Code is not able to open the session ( $session.Open($sessionOptions) ).代码无法打开会话( $session.Open($sessionOptions) )。

In the logs I found,在我发现的日志中,

Exception: System.MissingMethodException: Method not found: 'Void System.Threading.EventWaitHandle..ctor(Boolean, System.Threading.EventResetMode, System.String, Boolean ByRef, System.Security.AccessControl.EventWaitHandleSecurity)'. at WinSCP.ExeSessionProcess.TryCreateEvent(String name, EventWaitHandle& ev) at WinSCP.ExeSessionProcess.InitializeConsole() at WinSCP.ExeSessionProcess.Start() at WinSCP.Session.Open(SessionOptions sessionOptions) [2019-03-14 10:59:02.835Z] [0013] Session.Cleanup entering [2019-03-14 10:59:02.835Z] [0013] Terminating process

Basically, it jumps from $session.Open($sessionOptions) to $session.Dispose() and skipping other part of code.基本上,它从$session.Open($sessionOptions)跳转到$session.Dispose()并跳过代码的其他部分。

I tried to find solution here at WinSCP forum, but it didn't help:我试图在 WinSCP 论坛上找到解决方案,但没有帮助:
https://winscp.net/forum/viewtopic.php?t=26140 https://winscp.net/forum/viewtopic.php?t=26140

try {
    Add-Type -Path "M:\AMA\ztemp_powershell\WinSCPnet.dll" 

    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = "abc.xyz.ca"
        UserName = "abc_abc"
        Password = "*********"
        SshHostKeyFingerprint = "ssh-rsa 2048 **********************"
        PortNumber = 22
    }
    $session = New-Object WinSCP.Session   
    $session.ExecutablePath = "H:\FromLocal\Powershell\WinSCP.exe" 
    $filelist = Get-ChildItem M:\AMA\ztemp_powershell\sample_files

    try {
        # $session.DebugLogPath = "M:\AMA\ztemp_powershell\sftp1.log"
        $session.Open($sessionOptions)

        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary

        foreach ($file in $filelist) {
            $transferResult =  $session.PutFiles("M:\AMA\ztemp_powershell\sample_files\$file" , "/outbox/", $false, $transferOptions)

            foreach ($transfer in $transferResult.Transfers) {
                Write-Host "Upload of $($transfer.FileName) succeeded"
            }
        }
    }
    finally {
        $session.Dispose()
    }
    exit 0
}
catch {
    Write-Host "Error: $_"
    exit 1
}

You are most probably using PowerShell 6 or newer (aka PowerShell Core).您很可能正在使用 PowerShell 6 或更新版本(又名 PowerShell Core)。 These versions of PowerShell use .NET (Core), not .NET Framework.这些版本的 PowerShell 使用 .NET (Core),而不是 .NET Framework。

So you have to use the .NET Standard build of WinSCP .NET assembly.因此,您必须使用 WinSCP .NET 程序集的 .NET Standard 版本。 Inside the WinSCP-*-Automation.zip package , check the netstandard2.0 folder.WinSCP-*-Automation.zip包内,检查netstandard2.0文件夹。

Read about Installing the assembly for PowerShell .阅读有关为 PowerShell 安装程序集的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET EventWaitHandle 慢 - .NET EventWaitHandle slow 找不到方法:'无效Microsoft.PowerBI.Api.V1.PowerBIClient..ctor(Microsoft.Rest.ServiceClientCredentials,System.Net.Http.DelegatingHandler [])' - Method not found: 'Void Microsoft.PowerBI.Api.V1.PowerBIClient..ctor(Microsoft.Rest.ServiceClientCredentials, System.Net.Http.DelegatingHandler[])' .NET EventWaitHandle发出信号通知所有线程 - .NET EventWaitHandle signal all threads 使用 WinSCP .NET 程序集时 ...\\WinSCP.exe 的版本与此程序集的版本不匹配 - The version of ...\WinSCP.exe does not match version of this assembly when using WinSCP .NET assemly 在 SSIS 包中使用 WinSCP .NET 程序集时,“WinSCP.exe 的版本与此程序集的版本不匹配” - "The version of WinSCP.exe does not match version of this assembly" when using WinSCP .NET assembly in SSIS package 将.NET应用程序部署到生产中时,方法未找到异常 - Method no found exception when deploying my .NET application to production .net 使用 winscp 将文件从 windows 移动到 linux - .net moving file from windows to linux using winscp 使用 WinSCP .NET 程序集更改根 SFTP 目录 - Change root SFTP directory using the WinSCP .NET assembly 使用 PowerShell 和 WinSCP .NET 程序集计算上传文件的数量 - Count number of uploaded file using PowerShell and WinSCP .NET assembly WinSCP .NET WebDAV示例 - WinSCP .NET WebDAV Example
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM