Deleting files after transfer

Advertisement

dady
Joined:
Posts:
1

Deleting files after transfer

Hi all,

I'm using the following script to get files from SFTP. Everything is working great but now they came with a demand to delete the files on the source end after getting them.
Can someone help please.
Thanks in advance.
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
 
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "***.***.**"
    PortNumber = 8330
    UserName = "****"
    Password = "****"
    SshHostKeyFingerprint = "ssh-rsa 4096 rEjkMymlF6K/u182f70hLa7a0r7pwDze5oBRa0dk62U="
}
 
$sessionOptions.AddRawSettings("FSProtocol", "2")
 
$session = New-Object WinSCP.Session
 
try
{
    # Connect
    $session.Open($sessionOptions)
 
    # Transfer files
    $session.GetFiles("/*", "C:\Users\dady\Documents\*").Check()
   
}
finally
{
    $session.Dispose()
}

Reply with quote

Advertisement

kikinak72
Joined:
Posts:
1

Re: Deleting files after transfer

Hi,
Is it possible to do the same thing in script file ?

This is my script file
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# connect as ftp 
open "FTPOPEN"
# Force binary mode transfer
option transfer binary
# Change the remote directory
cd /.../
# Change the local directory
# Upload the file to current working directory
get /*.txt
# I want to delete files upload after the command GET
# Disconnect
close
# exit winscp
exit

Thanks

Reply with quote

Advertisement

You can post new topics in this forum