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

Author Message
saporter

Guest


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()
saporter

Guest


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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License