0

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
}
barbsan
  • 3,418
  • 11
  • 21
  • 28
Mr.Fix
  • 1
  • 1
  • VERBOSE: Performing the operation "Remove item from ftp location" on target "ftp://domain.com/.cagefs". VERBOSE: Use original path: ftp://domain.com/.cagefs VERBOSE: Remove additonal slash: ftp://domain.com/.cagefs VERBOSE: Path is directory VERBOSE: Use WebRequestMethods: LIST VERBOSE: Use original path: ftp://domain.com/.cagefs/. VERBOSE: Remove additonal slash: ftp://domain.com/.cagefs/. VERBOSE: Path is directory VERBOSE: Use WebRequestMethods: LIST VERBOSE: Use original path: ftp://domain.com/.cagefs/./. VERBOSE: Remove additonal slash: ftp://domain.com/.cagefs/./. – Mr.Fix May 17 '19 at 10:58
  • You can [edit] your question, don't add comments with description/error messages/additional code. Please, remove unnecessary `\`` from your code and add missing `ftp://` in your error message (it's invisible in comment, so I couldn't copy it) – barbsan May 17 '19 at 11:40
  • You're trying to remove directories by the look, if you're only after files, make sure your $output variable only has files, not folders – Scepticalist May 17 '19 at 17:50

0 Answers0