Getting Exception Calling "Get Response" with 0 arguments "this remote server returned an error"
Getting error message when I try to connect to this ftp. Strangely enough, it works when I log in with a different user account for the ftp but this one with correct credentials does not work...
$Date = Get-Date -format MM-dd-yyyy
$ftp = "ftp://ftp.makethiswork.com/"
$user = 'me'
$pass = 'help'
$folder = '/yes'
$target = "C:\Users\g\Desktop\VS Projects\Powershell\FTPDL\"
#SET CREDENTIALS
$credentials = new-object System.Net.NetworkCredential($user, $pass)
function Get-FtpDir ($url,$credentials) {
$request = [Net.WebRequest]::Create($url)
$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
if ($credentials) { $request.Credentials = $credentials }
$response = $request.GetResponse()
$reader = New-Object IO.StreamReader $response.GetResponseStream()
while(-not $reader.EndOfStream) {
$reader.ReadLine()
}
#$reader.ReadToEnd()
$reader.Close()
$response.Close()
Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (503) Bad sequence of commands." At line:16 char:9 + $response = $request.GetResponse() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException You cannot call a method on a null-valued expression. At line:17 char:9 + $reader = New-Object IO.StreamReader $response.GetResponseStr ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
$Date = Get-Date -format MM-dd-yyyy
$ftp = "ftp://ftp.makethiswork.com/"
$user = 'me'
$pass = 'help'
$folder = '/yes'
$target = "C:\Users\g\Desktop\VS Projects\Powershell\FTPDL\"
#SET CREDENTIALS
$credentials = new-object System.Net.NetworkCredential($user, $pass)
function Get-FtpDir ($url,$credentials) {
$request = [Net.WebRequest]::Create($url)
$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
if ($credentials) { $request.Credentials = $credentials }
$response = $request.GetResponse()
$reader = New-Object IO.StreamReader $response.GetResponseStream()
while(-not $reader.EndOfStream) {
$reader.ReadLine()
}
#$reader.ReadToEnd()
$reader.Close()
$response.Close()