- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 PowerShell 并使用 WinSCP .NET 程序集连接到 SFTP 服务器。
代码无法打开 session ( $session.Open($sessionOptions)
)。
在我发现的日志中,
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
$session.Open($sessionOptions)
跳转的至
$session.Dispose()
并跳过代码的其他部分。
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
}
最佳答案
您很可能正在使用 PowerShell 6 或更新版本(又名 PowerShell Core)。这些版本的 PowerShell 使用 .NET (Core),而不是 .NET Framework。
因此,您必须使用 WinSCP .NET 程序集的 .NET Standard 版本。内 WinSCP-*-Automation.zip
package ,查看 netstandard2.0
文件夹。
阅读 Installing the assembly for PowerShell .
关于.net - 使用 WinSCP .NET 的方法未找到异常 (EventWaitHandle..ctor),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55168750/
我试图理解我在网上找到的这段代码: private EventWaitHandle wh = new AutoResetEvent(); private void WorkerThread() {
我有一个 C# 程序可以像这样打开一个 EventWaitHandle 以被 Windows 服务触发。 EventWaitHandle sampleEventHandle = new EventWa
注意:我受限于 .NET 3.5,所以我不能使用 ManualResetEventSlim。 我必须处理Spurious wakeups吗?当做这样的事情时: var waitHandle = new
我有两个 Windows 应用程序,一个是创建 EventWaitHandle 并等待它的 Windows 服务。第二个应用程序是一个 Windows gui,它通过调用 EventWaitHandl
EventWaitHandle 可以跨进程使用。并且自动和手动重置事件仅在单个进程内。你能确认一下吗? 文档说自动/手动是本地的,它们不采用名称参数。所以我认为它们仅适用于流程内。对了,他们能跨app
我正在编写一个监听串行端口的程序。我已经有代码利用 VCP 驱动程序(虚拟 COM 端口)打开串行连接,然后为接收到的任何数据添加事件处理程序。该代码大致如下所示: public void OpenP
在进程 A 中,我需要从进程 B 接收事件。我决定使用 EventWaitHandle。在这两个过程中,我都写了这段代码: var evhandle = new EventWaitHandle(fal
有没有办法知道调用了哪个EventWaitHandle。 我有两个带有 2 个不同系统范围事件名称的自定义类。 我有它们的原因是为了区分触发哪个函数。 我现在的问题是如何区分触发了哪个事件? Even
考虑以下 MyServer 端的代码片段 public void CreateEvent() { var serverReadyEvent = new EventWaitHandle(false
从 albahari atricle 学习多线程.在下面的示例中我需要锁 _locker 吗?我想不会,因为 _message 受 EventWaitHandle 保护。我说得对吗? class Tw
我需要更改当前代码,以便在调用 EventWaitHandle.WaitOne 时不阻塞当前线程。问题是我正在等待系统范围的事件。我还没有找到任何合适的替代品。 代码: EventWaitHandle
这个网站的新手,所以如果我没有以可接受的方式发帖请告诉我。 我经常按照下面的示例编写代码(为清楚起见,省略了 Dispose 之类的内容。)。我的问题是,是否需要如图所示的 volatile ?或者
我想找到一种方法将这两行结合起来: cancellationToken.WaitHandle.WaitOne() |> ignore waitHandle.WaitOne() |> ignore 无论
我只是好奇,系统范围的 EventWaitHandle 的命名是否有任何限制?我想使用 URL 作为一个名称,但它可能有大量奇怪的字符,我不希望它默默地失败或其他类似的情况,所以只需检查这里是否有任何
我最近在 C# 中看到了 EventWaitHandle 的强大行为,并决定在姊妹应用程序中移动一些功能来实现同样的功能。唯一的问题是姊妹应用是用 C 语言编写的。 没什么大不了的,我正在使用 pth
我想要 EventWaitHandle 对象(例如 ManualResetEvent),它只能从一个地方设置/重置,但可以从多个地方等待(使用 WaitOne())。换句话说,我希望只有一个类可以设置
我猜这是一种代码审查,但这是我对生产者/消费者模式的实现。我想知道的是,在 ReceivingThread() 或 SendingThread() 方法中的 while 循环是否会停止执行。请注意,E
我有一个如下所示的任务类,一个任务只有在其依赖任务完成后才能开始运行。 class MyTask { List dependentTasks; public TaskStatus St
class Process { static void Main(string[] args) { int threads = 0; int proce
我有 3 个线程,两个“ worker ”和一个“经理”。 “工作人员”线程在 EventWaitHandle 上等待,“经理”线程将在增加其计数器后向 EventWaitHandle 发出信号。这些
我是一名优秀的程序员,十分优秀!