Following error is coming when trying to move the file from one folder (upload folder) to another (archive) which is available on SFTP server using WinSCP .NET assembly in 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
Following is the code which I am using to transfer the file:
# 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)