Skip to content

Instantly share code, notes, and snippets.

@thenathanjones
Created November 23, 2011 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenathanjones/1388178 to your computer and use it in GitHub Desktop.
Save thenathanjones/1388178 to your computer and use it in GitHub Desktop.
Test-FTP
param($URI, $Username, $Password)
function Test-FTP {
param($URI, $Username, $Password)
if (!$URI -or !$Username -or !$Password) {
throw "URI, Username and Password are all required"
}
$Error.Clear()
Write-Host "----- Attempting to connect to '$URI' with user '$Username'..." -NoNewLine
$Credentials = New-Object System.Net.NetworkCredential($username,$password)
$Request=[System.Net.FtpWebRequest]::Create($URI)
$Request.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory
$Request.Credentials=$credentials
$Response = $Request.GetResponse()
if ($Error.Count -gt 0) {
Write-Host
throw "Error connecting to '$URI' with user '$Username'"
}
Write-Host " OK"
}
Test-FTP -URI $URI -Username $Username -Password $Password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment