2017-10-11 12 views
2

한 폴더 (업로드 폴더)에서 PowerShell의 WinSCP .NET 어셈블리를 사용하여 SFTP 서버에서 사용할 수있는 다른 파일 (아카이브)로 파일을 옮기려고하면 다음 오류가 발생합니다. :PowerShell에서 WinSCP .NET 어셈블리를 사용하여 SFTP 서버의 파일 이름 바꾸기

# Connect 
$session.Open($sessionOptions) 

$existingFilepath = "/upload/attendance v2-201709220930.csv" 
$newFilepath = "/Archive/attendance v2-201709220930.csv" 

# Transfer files 
$session.GetFiles($existingFilepath,"C:\Transfer Files\Attendance Files\*").Check() 

$Sftp.RenameRemoteFile($existingFilepath,$newFilepath) 
+0

내 대답이 도움이 되었습니까? (나는 당신이 새로운 질문을 한 것을 본다) –

답변

1

사용 Session.MoveFile method는 :

$session.MoveFile($existingFilepath, $newFilepath) 

귀하의 코드가 어떤 의미하지 :

$Sftp.RenameRemoteFile($existingFilepath,$newFilepath) 
  • 코드에서 더 $sftp 변수가 없습니다은
  • WinSCP .NET assemblyRenameRemoteFile 방법이 없습니다 .
+0

안녕하세요, @martin, 이것은 $ session.MoveFile을 포함 할 때 발생하는 오류입니다 -------- --- 널 값 표현식에서 메소드를 호출 할 수 없습니다. C : \ Ratnesh \ Projects \ DCB-Bank \ Attendance Integration \ Scripts \ Power Shell 스크립트 \ Download & MoveToArchive.ps1 : 25 char : 5 + $ session.MoveFile ($ existingFilepath, $ newFilepath) .Check() + ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull –

+0

'$ session.GetFiles' 다음에'$ session.MoveFile'을 호출합니까? 'GetFiles' 작업과'MoveFile' 작업이 실패합니까? 전체 코드를 보여주십시오. –

+0

다음 코드는 작동 :'# 다운로드 파일 $ session.GetFiles ($ existingFilepath, $의 localpath를) .Check() # 이동 파일 업로드에서 보관 폴더 $ session.MoveFile ($ existingFilepath, $ newFilepath)에' –

0

당신은 할당 $Sftp 누락 :

You cannot call a method on a null-valued expression. 
At C:\Attendance Integration\Scripts\Power Shell 
Script\Download&MoveToArchive.ps1:28 char:5 
+  $Sftp.RenameRemoteFile($existingFilepath,$newFilepath) 
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
+ CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
+ FullyQualifiedErrorId : InvokeMethodOnNull 

다음 내가 파일을 전송하기 위해 사용하고있는 코드입니다.

+0

나는 '$ Sftp'의 과제를 놓치고 있습니까? –

+0

어디에도 보이지 않습니다. 임씨는 sftp에 익숙하지 않지만'RenameRemoteFile'을 호출하기 전에'$ Sftp' 어딘가에 할당해야합니다. –