While trying to delete files from ftp server using above script it loops on finding ./././././
directories which don't exist. Is there any error on the script or it's a bug in psftpd? Can anyone help me with the issue? Here is the looping lines copied from powershell console:
VERBOSE: Performing the operation "Remove item from ftp location" on target "ftp:/domain.com/.cagefs".
VERBOSE: Use original path: domain.com/.cagefs
VERBOSE: Remove additonal slash: domain.com/.cagefs
VERBOSE: Path is directory
VERBOSE: Use WebRequestMethods: LIST
VERBOSE: Use original path: domain.com/.cagefs.
VERBOSE: Remove additonal slash: domain.com/.cagefs.
VERBOSE: Path is directory
VERBOSE: Use WebRequestMethods: LIST
VERBOSE: Use original path: domain.com/.cagefs/..
VERBOSE: Remove additonal slash: domain.com/.cagefs/..
Code:
`Import-Module PSFTP`
`$FTPServer = 'domain.com'`
`$FTPUsername = 'username'`
`$FTPPassword = 'password'`
`$FTPSecurePassword = ConvertTo-SecureString -String $FTPPassword -asPlainText -Force`
`$FTPCredential = New-Object System.Management.Automation.PSCredential($FTPUsername,$FTPSecurePassword)`
`Set-FTPConnection -Credentials $FTPCredential -Server $FTPServer -Session MySession -UsePassive`
`$Session = Get-FTPConnection -Session MySession`
`$output = Get-FTPChildItem -Session $Session -Path '/' | Select ModifiedDate, Name | Where-Object {($_.ModifiedDate -lt (Get-Date).AddDays(-7))}|select name `
`echo $output`
foreach ( $file in $output ) {
Remove-FTPItem $file.name -Recurse -Session $Session -Verbose
}