0

How, i've made a program that uploads files on ftp server, the thing is that whenever i don't have access to the internet, it appears me an error, which stops running the program and says that i am not connected to the internet.

How do i make the program appear that message in a showmessage box, so that it doesn't stop running the program?

For example:

If internetconnection then
begin

end else showmessage ('You are not connected to the internet')
Sam
  • 7,252
  • 16
  • 46
  • 65
user2276109
  • 143
  • 1
  • 3
  • 7
  • 6
    Try to connect to that FTP server. By doing so you will also verify that the FTP server is alive. – TLama Apr 15 '13 at 17:48
  • try [InternetCheckConnection](http://stackoverflow.com/questions/843810/fastest-way-to-test-internet-connection) – RRUZ Apr 15 '13 at 18:13
  • 3
    What components are you using to do your ftp? The components you're using (Indy, ICS, or something else) makes a difference in how this question is answered. "uploads files on ftp" means nothing. – Ken White Apr 15 '13 at 18:23
  • 2
    @RRUZ: `InternetCheckConnection()` is not reliable. – Remy Lebeau Apr 16 '13 at 00:17

1 Answers1

-2

Please try code from this link

Ping

Also you can try to use free Internet Component Suite components that allows to implement test connection to your ftp server.

EDIT:

Since it was found that the author uses IdFTP (Indy) component for upload files on ftp server and my first answer was not good i will take courage to write as i think correct code for checking connection to the ftp server:

with IdFTP1 do begin
  Host := ..;
  Port := ..;
  Username := ..;
  Password := ..;
  if Connected then Disconnect;
  try
    Connect;
    ShowMessage('FTP IS Connected')
  except
    ShowMessage('FTP IS NOT Connected');
  end;
end;
Konstantin
  • 796
  • 1
  • 11
  • 32
  • Though this might answer the question, it won't resolve the problem. Consider that user of OP's application might be able to connect to the Internet, but will have denied access to any FTP connection for instance. I'm still for an attempt to connect to the target FTP server. And please don't post link only answers. [no voting here] – TLama Apr 15 '13 at 17:56
  • The code from question shows that the author would like to check internet connection in general. As to my post if the author wishes to understand the problem in details he may go to the link and see more detail example. I am sorry, I should have write a comment instead of answer. – Konstantin Apr 15 '13 at 18:05
  • Thanks guys. What Tlama told me works: If idftp1.conntected=true then.....else showmessage ('There is no access to the internet '); – user2276109 Apr 15 '13 at 18:22
  • 1
    Two links to off-site locations are not an answer here. If those links are off-line or are moved in the future, the entire answer becomes meaningless. Your answer should contain enough information to answer the question *here*. Use links off-site as additional reference material, but not as the majority of the content. (The exception is links to major sites like MS that can be pretty certain to stay there for a very long time.) – Ken White Apr 15 '13 at 18:26
  • Just because the component failed to connect to the FTP site doesn't necessarily mean that there is no internet connection. Suppose there's a temporary drop in your DNS server, for example, which in turn makes the component fail to connect. Or, suppose the FTP site is temporarily down. Or, the FTP server is blocking your connection. None of these mean that you don't have an internet connection. – Jerry Dodge Apr 15 '13 at 18:37
  • OK. I will take note of your useful comment. You know, the answer confused me. – Konstantin Apr 15 '13 at 18:40