Groups > Web Hosting > IIS FTP > Re: FTP Error




FTP Error

FTP Error
Fri, 4 Aug 2006 18:22:14 +0000
I have a requirment to write code to login to an ftp site and upload a specific
text file. I have written the following code, but when I run the code, it gives
me an error message "Unable to connect to the remote server" I have
checked the ftp site and the user id and password. Everything thing is correct,
but the code won't work. Please help. Your valuable feedback is greatly
appriciated.

  Public Function Upload() As FtpStatusCode
        Dim request As FtpWebRequest = Nothing
        Dim response As FtpWebResponse = Nothing
        Dim sr As StreamReader = Nothing
        Dim sw As StreamWriter = Nothing

        Dim UploadUri As New Uri("ftp://198.168.1.6/") 

        Try
            ' Check if the URI is and FTP site
            If Not (UploadUri.Scheme = Uri.UriSchemeFtp) Then
                Throw New ArgumentException("URI is not an FTp site")
            End If

            request = CType(FtpWebRequest.Create(UploadUri), FtpWebRequest)
            request.Method = WebRequestMethods.Ftp.UploadFile
            request.Proxy = Nothing 
            request.Credentials = New
System.Net.NetworkCredential("codejkl", "ftppass_321*")

            sw = New StreamWriter(request.GetRequestStream, Encoding.UTF8) ' Not
to sure if this is right encoding?
            sr = New StreamReader("C:\test\Test.txt")

            sw.Write(sr.ReadToEnd)

            response = CType(request.GetResponse, FtpWebResponse) 
            Return response.StatusCode
        Catch ex As WebException
            Throw New ApplicationException("FtpUpload Failed: " &
ex.Message, ex)
        Catch ex As Exception
            Throw ex
        Finally
            If response IsNot Nothing Then response.Close()
            If sr IsNot Nothing Then sr.Close()
            If sw IsNot Nothing Then sw.Close()
        End Try
    End Function
End Class
Post Reply
Re: FTP Error
Wed, 9 Aug 2006 17:06:31 +0000
Hi coolvaas1,

Did you notice that you left your password in the example?  You may want to
double check that you've updated that and don't use it anymore, just in case.  I
notice that the IP address is 198.168.1.6.  Did you mean for that to be
192.168.1.6 which is a common non-public IP address?

You can test for connectivity using the command prompt:

telnet ipaddress 21

That will confirm that your computer has FTP access to a particular IP and port.
 From skimming your code, it looks good.

Thanks,

Scott
Post Reply
Re: FTP Error
Thu, 10 Aug 2006 13:57:34 +000
Hi Scott,
Thanks for the feed back. Well I did not leave the password out.
If you look at the line :
request.Credentials = New System.Net.NetworkCredential("codejkl",
"ftppass_321*")
second parameter is the ftp password.
Yes the ip address is correct. It is in our local network and I can connect to
the ftp site using telnet and web browser.
I am not sure why it is not working in the code.
Please help
Post Reply
Re: FTP Error
Fri, 11 Aug 2006 05:44:20 +000
If it works if you ftp manually, then it is something in your code that is not
working.
When you get the error msgs, does IIS FTP log capture the connecting request ?
or it didn't reach IIS ftp at all?
Post Reply
Re: FTP Error
Fri, 11 Aug 2006 15:30:01 +000
I meant that you displayed your password to the world.  It sounds like you're ok
with that, I just wanted to make sure you didn't do that by mistake.  (It's been
done before).

What happens if you do the telnet test?  I still think that it is probably your
IP address.  198.168.1.6 isn't an internal IP address so it will only work for
you if your router is purposefully set up that way.  The telnet test will tell
you for sure.  The internet subnet to use is 192.168.1.x (notice the 198 -vs-
192)

Scott
Post Reply
<< Previous 1 2 3 4 Next >>
( Page 1 of 4 )
about | contact