PowerShell cannot find overload
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)
Comments
-
Kirk almost 2 years
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.The definition of the method is 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'm trying to use this overload
UploadFile(System.IO.Stream input, string path, System.Action[uint64] 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.
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")
Fails 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 next attempts all fail with the same error message essentially
$action = [System.Action[uint64]] $client.UploadFile($sourceStream, "$ftpPath$output", $action)
Error
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
Attempted with a
$null
3rd parameter$client.UploadFile($sourceStream, "$ftpPath$output", $null)
Failed with
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