I am trying to get the name of the last modified file (and subsequently download later) on the FTP site through powershell. But I am unable to get the results. If someone can point me to the right direction, that would be really great. Thank you very much.
$ftpPath = 'ftp://ftpsite/'
function Get-FtpDir ($url) { $request = [Net.FtpWebRequest]::Create($url)
$request.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory
$response = $request.GetResponse()
$reader = New-Object IO.StreamReader $response.GetResponseStream()
$reader.ReadToEnd()
$reader.Close()
$response.Close()
}
$webclient = New-Object System.Net.WebClient
$webclient.BaseAddress = $ftpPath
$files = Get-FTPDir $ftpPath
$latest = $Files | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$latest