使用if else语句获取IP地址并下载数据 [英] using if else statment for IP address and download the data

查看:110
本文介绍了使用if else语句获取IP地址并下载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个设备具有单独的IP地址,并且想要检查是否有任何一个连接并且如果已连接从设备下载数据库,并且在任何给定时间只连接了一个设备。我的查询适用于一个设备如何检查是否另一个IP地址。



I have two devices having separate IP addresses and want to check if any one is connected and if connected download the database from the device and any given time only one device is connected.My query works fine for one device how to check if ahve another IP address.

string _ftpURL = @"100.100.00.0";  //Host URL or address of the SFTP server
 string _UserName = "root"; //fake User Name of the SFTP server
            string _Password = "310rp3"; // fake Password of the SFTP server
            int _Port = 2222; //Port No of the SFTP server (if any)
            string _ftpDirectory = "/home/root/systools/WM/WebMobility.db"; //The directory in SFTP server where the files will be uploaded
            string LocalDirectory = "F:\\Explor\\final test"; //Local directory from where the files will be uploaded
            Sftp Connection = new Sftp(_ftpURL, _UserName, _Password);
            Connection.Connect(_Port);
            Connection.Get(_ftpDirectory, LocalDirectory);
            Connection.Close();





因为我必须检查哪个Ipaddress已连接,所以我很震惊。:101.00。 00.0。(第二个IP地址)



I am struck here as I have to check which Ipaddress is connected .:101.00.00.0.(2nd Ip address)

推荐答案

我想我可能会错过阅读你的帖子。 :(

看来你只有2台服务器需要检查,你知道他们的IP地址是什么。



你可以尝试一下像这样:

I think I may have miss read your post. :(
It appears you only have 2 servers to check, and you know what their IP Address are.

You could then try something like this:
string[] _ftpURL = { @"100.100.0.0", @"101.0.0.0" };  //Array of address to SFTP servers
string _UserName = "root"; //fake User Name of the SFTP server
string _Password = "310rp3"; // fake Password of the SFTP server
int _Port = 2222; //Port No of the SFTP server (if any)
string _ftpDirectory = "/home/root/systools/WM/WebMobility.db"; //The directory in SFTP server where the files will be uploaded
string LocalDirectory = "F:\\Explor\\final test"; //Local directory from where the files will be uploaded
bool online = false;
foreach(string furl in _ftpURL)
{
     Sftp Connection = new Sftp(furl, _UserName, _Password);
     try
     {
          Connection.Connect(_Port);
          online = true;
     }
     catch
     {
          online = false;
     }
     if(online == true)
     {
          Connection.Get(_ftpDirectory, LocalDirectory);
          Connection.Close();
          break;
     }
}


这篇关于使用if else语句获取IP地址并下载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆