We help IT Professionals succeed at work.
Get Started

Trying to code for webexecptions

NevSoFly
NevSoFly asked
on
516 Views
Last Modified: 2010-04-21
The solution for this related question works great.  My new question is :

How can I code for the following webexecptions that I know will happen in my code:
     1.   The remote server returned an error:(550) File unavailable (e.g., file not found, no access).
     2.   The operation has timed out.

I need to handle these execptions differently but I can't seem to find the correct execption types

How can I find out if a file on the ftp server exists?

url="FTP://MyFTPSite"
 
Public Function DownloadFile(ByVal url As String) As Byte()
 
        'If you have a valid user name and password, then supply it here
        '  This assumes an annonymous user
        Dim userName As String = "MyUserName"
        Dim password As String = "xxxxx"
 
        'Create Credentials to include user name and password
        Dim Creds As System.Net.NetworkCredential
        Creds = New System.Net.NetworkCredential(userName, password)
 
        'Create the WebClient and provide the credentials
        Dim request As New Net.WebClient
        request.Credentials = Creds
 
        'Check to see if file exits.
        If request.DownloadData(url).Rank > 0 Then
            'Download the file to a byte array
            Dim fileData As Byte() = request.DownloadData(url)
            Return fileData
        Else
            Return Nothing
        End If
 
    End Function

Open in new window

Comment
Watch Question
Technical Manager
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE