小编PJS*_*PJS的帖子

Delete files older than X days from FTP server with PowerShell or batch file

I have to write a script which accesses an FTP server, and then deletes all *.zip files which are older than X days.

As clarification: The script can't run on the FTP server.

This is what I have so far:

$ftpServer = "RandomFTPServer"
$ftpUser = "Username"
$ftpPassword = Read-Host "Password" -AsSecureString

$credentials = New-ObjectSystem.Net.NetworkCredential($ftpUser, $ftpPassword)

function Get-FtpRequest($ftpPath) {
    $ftpRequest = [System.Net.FtpWebRequest]::Create("$ftpServer/$ftpPath")
    $ftpRequest.Credentials = $credentials
    $ftpRequest.UseBinary = $true 
    $ftpRequest.KeepAlive = $true
    $ftpRequest.UsePassive = $true
    return $ftpRequest
}
Run Code Online (Sandbox Code Playgroud)

Any tips on what …

.net ftp powershell batch-file ftpwebrequest

4
推荐指数
1
解决办法
7816
查看次数

标签 统计

.net ×1

batch-file ×1

ftp ×1

ftpwebrequest ×1

powershell ×1