Created
November 23, 2011 08:26
-
-
Save thenathanjones/1388178 to your computer and use it in GitHub Desktop.
Test-FTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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