Translate

недеља, 23. октобар 2016.

FTP

Vec sam postavio skriptu za Upload na FTP sajt a evo sad i dodatne dve funkcije koje listaju fajlove na FTP serveru i brisu

function Get-FtpDir {
param($url, $credentials)
begin{

  $request = [Net.FtpWebRequest]::Create($url)
  if ($credentials) { $request.Credentials = $credentials }
  $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
  (New-Object IO.StreamReader $request.GetResponse().GetResponseStream()).ReadToEnd() -split "`r`n"
}}


function Remove-FtpFile{
param ($url, $credentials)
begin {
  $request = [System.Net.FtpWebRequest]::create($url)
  if ($credentials) { $request.Credentials =  $credentials }
  $request.Method = [System.Net.WebRequestMethods+Ftp]::DeleteFile
  [Void] $request.GetResponse()
}}


Primeri za koriscenje ovih funkcija su:

Get-FtpDir -url 'someftpaddress' -credentials get-credentials
Remove-FtpFile ("$ftpPath/FileName.txt") -credentials get-credentials