重命名SFTP服務器上的文件,WinSCP賦予.NET程序集以下錯誤來當試圖將文件從一個文件夾(文件夾上傳)移動到另一個(存檔),這是可以使用WinSCP賦予.NET程序集在PowerShell中SFTP服務器上:在PowerShell中
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
下面是我使用的傳輸文件代碼:
# 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)
難道我的回答幫助? (因爲我看到你問了一個新問題) –