How to detect working internet connection in C#?

2019-01-10 09:10发布

I have a C# code that basically uploads a file via FTP protocol (using FtpWebRequest). I'd like, however, to first determine whether there is a working internet connection before trying to upload the file (since, if there isn't there is no point in trying, the software should just sleep for a time and check again).

Is there an easy way to do it or should I just try to upload the file and in case it failed just try again, assuming the network connection was down?

7条回答
在下西门庆
2楼-- · 2019-01-10 09:45

Can't you just use the Ping Class of the System.Net.NetworkInformation Namespace to ping the FTP server before trying to upload the file?

查看更多
登录 后发表回答