Powershell WinSCPnet, not deleting remote files when using $session.RemoveFiles()
Hi,
I struggle to get the
The errormessage I get is "{WinSCP.SessionRemoteException: Can't get attributes of file "
This is the barebone code I am trying.
Grateful for any assistance, or alternative ways to solve the problem
I struggle to get the
RemoveFiles()
function to delete remote files. Using the WinSCPnet in a PowerShell script.
The errormessage I get is "{WinSCP.SessionRemoteException: Can't get attributes of file "
This is the barebone code I am trying.
Grateful for any assistance, or alternative ways to solve the problem
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll" $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::ftp HostName = "xxxxx" UserName = "xxxxx" password = "xxxxx" } $session = New-Object WinSCP.Session $session.ExecutablePath = "C:\Program Files (x86)\WinSCP\winscp.exe" try { # Connect $session.Open($sessionOptions) $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary #Listing remote directory to avoid the problem of how the file is named. # NOT all remote files should be deleted, in real life I would like to loop through a list # local filenames that should be deleted on the remote location $Directory = $session.ListDirectory("/") foreach ($FileInfo in $Directory.Files) { $RemovalFile = ($FileInfo.Name) $session.RemoveFiles($RemovalFile) } } finally { $session.Dispose() }