PowerShell cannot find overload
I am trying to use https://sshnet.codeplex.com/ to let a PowerShell script upload a file to an SFTP server. Everything seems to work, except that it cannot find the method overload UploadFile
and is lost.
Method definition here
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)
I am trying to use this overload
UploadFile(System.IO.Stream input, string path, System.Action[uint64] uploadCallback)
The field uploadCallback
is optional as per the documentation and not required in my simple script but even adds that on error. The ways I've tried calling this are as follows: they all fail.
How do I call one of these methods successfully? Examples of what I've tried are below.
<strong> Examples
$client = New-Object Renci.SshNet.SftpClient($ftpHost, $ftpPort, $ftpUser, $ftpPass)
$client.Connect()
# ... get stream of file to upload here ...
$client.UploadFile($sourceStream, "$ftpPath$output")
Crashing with
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 following attempts all fail with the same error message substantially
$action = [System.Action[uint64]]
$client.UploadFile($sourceStream, "$ftpPath$output", $action)
Mistake
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
Trying with $null
third parameter
$client.UploadFile($sourceStream, "$ftpPath$output", $null)
Failed to execute
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
source to share