Move file on Remote Server to Different Folder After Download (SFTP)?
I have a look through a list of Posh-SSH command,
I can't seem to find a command to move a file to archive folder on the Remote Server. eg: Remote Folder: /Out Remote Folder: /Out/Archive
I can see that there is a delete file command (https://github.com/darkoperator/Posh-SSH/blob/master/docs/Remove-SFTPFile.md) on the Remote Server Command (Similar to the following request #156 )
To Safe guard a failed download.
Thanks.
You are correct, will work on adding one
can you tell us when the command rename-sftpfile (in different remote folder) will work ?
Thanks, Emeline
No ETA on it at this time.
On Dec 18, 2017, at 10:43 AM, Emeline05 [email protected] wrote:
can you tell us when the command rename-sftpfile (in different remote folder) will work ?
Thanks, Emeline
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/darkoperator/Posh-SSH/issues/178#issuecomment-352444820, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HmdAQjhlsqi0UvCN6dAhX25hSv2rks5tBnorgaJpZM4Px52P.
This works for me:
Rename-SFTPFile -SessionId $sftp.SessionId -Path $remoteFileInfo.FullName -NewName "./Archive/$($remoteFileInfo.Name)"
Trying to use Rename-SFTPFile and it will work if I put the file in the root directory of the SFTP server, /aaa.txt. If I try to use the function with a file in a directory it will throw an exception "Exception calling "RenameFile" with "2" argument(s): "File not found""
The file is there and the directory path is correct Rename-SFTPFile -SessionId $session.SessionID -Path "/Outbound/aaa.txt" -NewFile "/Outbound/bbb.txt" If I add the verbose flag it just shows me the paths above and tells me that it's renaming it.
Also, I am able to use Get-SFTPChildItem with no problem in this Outbound folder $files = Get-SFTPChildItem $session -Path '/Outbound'
For what it's worth, I ran into the same "File not found" error myself and solved it by setting a relative path for the parameter -NewName. An absolute path won't work for -NewName because the file you supply in -Path is parsed, extracting the folder structure and prepended it to the destination filename. ex. Rename-SFTPFile -SessionId $session.SessionID -Path "/Outbound/aaa.txt" -NewFile "bbb.txt" ex. Rename-SFTPFile -SessionId $session.SessionID -Path "/sub1/sub2/myfile.txt" -NewFile "../myfile.txt"
That is odd and unexpected behavior. Thanks for the info. Since I've got it working with a work around I'm loath to want to risk breaking it ;)