gpt4 book ai didi

.net - PowerShell 找不到过载

转载 作者:行者123 更新时间:2023-12-04 23:02:57 26 4
gpt4 key购买 nike

我正在尝试使用 https://sshnet.codeplex.com/允许 PowerShell 脚本将文件上传到 SFTP 服务器。一切似乎都有效,只是找不到方法的重载 UploadFile我难住了。

该方法的定义在这里

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根据文档是可选的,在我的简单脚本中不需要,但即使添加它也失败。我试过调用它的方法如下,它们都失败了。

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

示例
$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

下一次尝试都失败了,基本上是相同的错误消息
$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 提供更多帮助,例如:

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

关于.net - PowerShell 找不到过载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26414618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com