Posh-SSH icon indicating copy to clipboard operation
Posh-SSH copied to clipboard

Move file on Remote Server to Different Folder After Download (SFTP)?

Open datauduong opened this issue 8 years ago • 7 comments

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.

datauduong avatar Oct 08 '17 23:10 datauduong

You are correct, will work on adding one

darkoperator avatar Oct 09 '17 00:10 darkoperator

can you tell us when the command rename-sftpfile (in different remote folder) will work ?

Thanks, Emeline

Emeline05 avatar Dec 18 '17 14:12 Emeline05

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.

darkoperator avatar Dec 18 '17 15:12 darkoperator

This works for me:

Rename-SFTPFile -SessionId $sftp.SessionId -Path $remoteFileInfo.FullName -NewName "./Archive/$($remoteFileInfo.Name)"

alekti avatar Oct 18 '18 19:10 alekti

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'

davedoc avatar Jul 16 '20 21:07 davedoc

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"

rbenchetrit avatar Dec 16 '20 16:12 rbenchetrit

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

davedoc avatar Dec 16 '20 17:12 davedoc