2014-10-16 4 views
3

https://sshnet.codeplex.com/을 사용하여 PowerShell 스크립트에서 파일을 SFTP 서버에 업로드 할 수 있습니다. UploadFile 메서드의 오버로드를 찾을 수 없다는 것을 제외하고는 모든 것이 제대로 작동하는 것처럼 보입니다.PowerShell에서 오버로드를 찾을 수 없습니다.

방법의 정의는 여기에 내가이 오버로드

UploadFile(System.IO.Stream input, string path, System.Action[uint64] uploadCallback) 

uploadCallback이 문서에 따라 선택 사항이며 내 간단한에서 필요하지 않은 필드를 사용하기 위해 노력하고있어

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) 

입니다 스크립트를 추가하지만 실패하더라도이를 추가하십시오. 내가 이것을 부르려고했던 방법은 다음과 같다. 그들은 모두 실패했다.

어떻게 이러한 메서드 중 하나를 성공적으로 호출 할 수 있습니까? 내가 시도한 것들의 예가 아래에있다.

$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) 

오류

515,는

$client.UploadFile($sourceStream, "$ftpPath$output", $null) 

함께 실패 $null 3 매개 변수를 시도

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 
+1

$ client.UploadFile ($ sourceStream, "$ ftpPath $ output", [Action [uint64]] $ null)'을 사용해보십시오. 또한, $ sourceStream은 스트림입니까? 즉'$ sourceStream -is [System.IO.Stream]'은 True를 리턴합니까? –

+0

이 게시물을 트림하는 것이 도움이 될 수 있습니다. 문제의 고기를 얻기 위해서는 많은 일이 필요합니다. 어쩌면 다시 구성하여 더 중요한 세부 사항을 시작할 수도 있습니다. – jpmc26

+0

@KeithHill 그게 문제 였어, 나는'Stream' 대신'StreamReader'를 전달하고있었습니다. 당신이 대답을 작성하면 받아 들일 테니, 고마워요. – Kirk

답변

4

메소드 호출 등의 캐스팅으로 유형의 정보를 제공하여 PowerShell을 조금 더 도움을주고보십시오 :

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