Bir FTP sitesinden dosyaları çekecek bir PowerShell betiği üzerinde çalışıyorum. Dosyalar her saat başı FTP sitesine yüklenir, bu yüzden en güncel olanı indirmem gerekir. Şu anda kullandığım kod şu anda sadece bir dosya yerine tüm dosyaları indiriyor. Sadece en yeni dosyayı nasıl indirebilirim? İşte En son dosyayı PowerShell kullanarak FTP'den yükleyin
Şu anda buFtpWebRequest
ile kolay değil
$ftpPath = 'ftp://***.***.*.*'
$ftpUser = '******'
$ftpPass = '******'
$localPath = 'C:\Temp'
$Date = get-date -Format "ddMMyyyy"
$Files = 'File1', 'File2'
function Get-FtpDir ($url, $credentials)
{
$request = [Net.FtpWebRequest]::Create($url)
if ($credentials) { $request.Credentials = $credentials }
$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
(New-Object IO.StreamReader $request.GetResponse().GetResponseStream()) -split "`r`n"
}
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($ftpUser,$ftpPass)
$webclient.BaseAddress = $ftpPath
Foreach ($item in $Files)
{
Get-FTPDir $ftpPath $webclient.Credentials |
? { $_ -Like $item+$Date+'*' } |
% {
$webClient.DownloadFile($_, (Join-Path $localPath $_))
}
}
WinSCP büyük yarar ve – Jimbo
WinSCP kayalar :) çok güvenilir olduğunu (WinSCP yazarı değilim). PowerShell ile FTP transferi için oldukça etkilidir. – sodawillow