Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

ricedave

how to delete fives older than x amount of days

The below Powershell script connects to my SFTP sever and deletes all my files under the path /test/my_file/.

Is there a way where I can say only delete files that is five days old under the path /test/my_file/

Add-Type -Path " WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "example.test.com"
UserName = "username"
Password = "password"
SshHostKeyFingerprint = "ssh-rsa 1234 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}

$sessionOptions.AddRawSettings("ProxyMethod", "0")
$sessionOptions.AddRawSettings("ProxyHost", "123.45.67.8")
$sessionOptions.AddRawSettings("ProxyPort", "8080")

$session = New-Object WinSCP.Session

try
{
$session.Open($sessionOptions)

# Remove files
$session.RemoveFiles("/test/my_file/*").Check()
}
finally
{
$session.Dispose()
}
thank you in advance.