Don't quite understand how to write get with - delete in powershell

Advertisement

saporter
Guest

Don't quite understand how to write get with - delete in powershell

Hello!
I've looked at some examples for how to delete a file after it is downloaded, using get -delete, but I don't quite understand how to write this in powershell. Using winscp 5.7.6, and powershell 3, I'm trying to sftp to a Linux server and download a file, and delete the file after it has downloaded. I can download the file but I don't know how to delete it from the server afterward. Here is my code:

# connect
$session.Open($sessionOptions)

# download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary

$transferResult = $session.GetFiles("/directory/XDOWNLOADS/fileA", "c:\windowsdirectory\fileA", $False, $transferOptions)

# Disconnect
$session.Dispose()

Reply with quote

saporter
Guest

Re: Don't quite understand how to write get with - delete in powershell

Oh, I may have figured it out- I may just have to change $False to $True...

$transferResult = $session.GetFiles("/directory/XDOWNLOADS/fileA", "c:\windowsdirectory\fileA", $False, $transferOptions)

if that doesn't work I'll look at $session.removefiles

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: Don't quite understand how to write get with - delete in powershell

saporter wrote:

Oh, I may have figured it out- I may just have to change $False to $True...
Correct. Set the remove argument of the Session.GetFiles to $True:

$transferResult = $session.GetFiles("/directory/XDOWNLOADS/fileA", "c:\windowsdirectory\fileA", $True, $transferOptions)

See:
https://winscp.net/eng/docs/library_session_getfiles
https://winscp.net/eng/docs/scriptcommand_get#net

Reply with quote

Advertisement

You can post new topics in this forum