Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.3k views
in .NET FTP by (220 points)
How do I verify or return a value if there is a connection error (can't find server, user isn't connected to the internet, etc.)?
Will this work?

ftp.ServerAddress = "1.1.1.1"
ftp.ServerPort = 21
ftp.UserName = "username"
ftp.Password = "password"
ftp.Connect()
If ftp.IsConnected = False Then
  MsgBox("Unable to connect to the server. Please verify that you are connected to the internet and try again.", MsgBoxStyle.Critical, "WARNING")
  Return
Else : End If

4 Answers

0 votes
by (51.6k points)
Try
  ftp.Connect()
Catch ex As Exception
  MsgBox("Unable to connect to the server. Please verify that you are connected to the internet and try again.", MsgBoxStyle.Critical, "WARNING")
End Try
0 votes
by (220 points)
That worked just fine, one more question..
I'm getting a 'getsize' error 500 - It would appear from my web searching, that our server doesn't accept that command. Is there a way around this?
I'm trying to verify the file transferred by comparing original file size to destination file size. I don't care how I verify as long as it is accurate.
Any help is appreciated.
0 votes
by (162k points)
You could use GetFileInfos() on the directory. However if the file transferred without an exception, it is reasonable to expect that it transferred correctly.
0 votes
by (220 points)
I'll try that..
I suppose I could even use the Try Catch code for the ftp.upload process as well. If it errors I'll know..
thanks for helping me think this through!

Categories

...