PowerShell cannot find overload

I'm attempting to use 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 
4

1 Answer

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) 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like