我试图使用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)
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用此重载
UploadFile(System.IO.Stream input, string path, System.Action[uint64] uploadCallback)
Run Code Online (Sandbox Code Playgroud)
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")
Run Code Online (Sandbox Code Playgroud)
与失败
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
Run Code Online (Sandbox Code Playgroud)
下次尝试都将失败,并且本质上是相同的错误消息
$action = [System.Action[uint64]]
$client.UploadFile($sourceStream, "$ftpPath$output", $action)
Run Code Online (Sandbox Code Playgroud)
错误
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
Run Code Online (Sandbox Code Playgroud)
尝试使用$null第三个参数
$client.UploadFile($sourceStream, "$ftpPath$output", $null)
Run Code Online (Sandbox Code Playgroud)
失败
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
Run Code Online (Sandbox Code Playgroud)
尝试通过在方法调用中提供类型信息来为PowerShell提供更多帮助,例如:
$client.UploadFile($sourceStream, "$ftpPath$output", [Action[uint64]]$null)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8912 次 |
| 最近记录: |