在尝试使用上述脚本从 ftp 服务器中删除文件时,它会循环查找./././././
不存在的目录。脚本上是否有任何错误或它是 psftpd 中的错误?谁能帮我解决这个问题?这是从 powershell 控制台复制的循环行:
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/..
代码:
`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
}