PowerShell找不到重载 [英] PowerShell cannot find overload

查看:79
本文介绍了PowerShell找不到重载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 https://sshnet.codeplex.com/允许使用PowerShell脚本将文件上传到SFTP服务器.一切似乎都可以正常工作,除了找不到方法 UploadFile 的重载并陷入困境.

I'm attempting to use https://sshnet.codeplex.com/ to allow a PowerShell script to upload a file to a SFTP server. Everything appears to work, except it cannot find an overload of the method UploadFile and am stumped.

方法的定义在这里

TypeName   : Renci.SshNet.SftpClient
Name       : UploadFile
MemberType : Method
Definition : void UploadFile(System.IO.Stream input, string path, System.Action[uint64] uploadCallback),
             void UploadFile(System.IO.Stream input, string path, bool canOverride, System.Action[uint64] uploadCallback)

我正在尝试使用此重载

UploadFile(System.IO.Stream input, string path, System.Action[uint64] uploadCallback)

根据文档,字段 uploadCallback 是可选的,在我的简单脚本中不需要,但是即使添加该字段也会失败.我尝试使用此方法的方法如下,但都失败了.

The field uploadCallback is optional according to the documentation and isn't needed in my simple script, but even adding that in fails. The ways I've tried calling this with is as follows, they all fail.

如何成功调用这些方法之一?下面是我尝试过的示例.

How do I successfully call one of these methods? Examples of what I tried are below.

示例

$client = New-Object Renci.SshNet.SftpClient($ftpHost, $ftpPort, $ftpUser, $ftpPass)
$client.Connect()

# ... get stream of file to upload here ...

$client.UploadFile($sourceStream, "$ftpPath$output")

失败

Cannot find an overload for "UploadFile" and the argument count: "2".
At F:\MyScript.ps1:170 char:2
+     $client.UploadFile($sourceStream, "$ftpPath$output")
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

下次尝试基本上都失败,并显示相同的错误消息

The next attempts all fail with the same error message essentially

$action = [System.Action[uint64]]
$client.UploadFile($sourceStream, "$ftpPath$output", $action)

错误

Cannot find an overload for "UploadFile" and the argument count: "3".
At F:\MyScript.ps1:170 char:2
+     $client.UploadFile($sourceStream, "$ftpPath$output", $action)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

尝试使用 $ null 第三个参数

$client.UploadFile($sourceStream, "$ftpPath$output", $null)

失败

Cannot find an overload for "UploadFile" and the argument count: "3".
At F:\MyScript.ps1:169 char:2
+     $client.UploadFile($sourceStream, "$ftpPath$output", $null)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

推荐答案

尝试通过提供方法调用中提供的类型信息为PowerShell提供更多帮助,例如:

Try giving PowerShell a bit more help by providing the type info as cast in the method call e.g.:

$client.UploadFile($sourceStream, "$ftpPath$output", [Action[uint64]]$null)

这篇关于PowerShell找不到重载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆