private ArrayList alst = new System.Collections.ArrayList();//建立ArrayList对象
int strLength = 0;
string dirSub = null;
private Ftp ftpClient;

public FormSearch()
{
InitializeComponent();
InitProduct("/allData/5/");
}

//产品类型初始化
private void InitProduct(string dir)
{
ftpClient = new Ftp("ftp://ladsweb.nascom.nasa.gov", "anonymous", "rufeixida@sina.com");
string[] remoteContents = ftpClient.directoryList(dir);
if (remoteContents != null)
{
foreach (string strRemote in remoteContents)
{
if (strRemote == "")
{
break;
}
else
{
if (strRemote.Contains("MOD") || strRemote.Contains("MYD"))
comboProduct.Items.Add(strRemote);
}
}
}
}
//递归实现搜索
private void GetFiles(string dir, Ftp ftpClient)
{
if (dir == "" || dir == null)
MessageBox.Show("文件搜索完成");
else
{
string[] remoteContents = ftpClient.directoryList(dir);
if (remoteContents != null)
{
foreach (string strRemote in remoteContents)
{
if (strRemote == "")
{
dirSub = dir.Substring(0, dir.Length - strLength);
break;
}
else
{
string strTime = null;
string exname = strRemote.Substring(strRemote.LastIndexOf(".") + 1);//得到后缀名 
if (strRemote.Length > 10)
{
strTime = strRemote.Substring(strRemote.IndexOf(".") + 2, 7);//得到时间
}
if (".hdf".IndexOf(strRemote.Substring(strRemote.LastIndexOf(".") + 1)) > -1 && strRemote.Contains(NumberTxtBox.Text) && checkTime(strTime, this.dateTimePicker1.Text, this.dateTimePicker2.Text))
{
alst.Add(strRemote);//把.hdf文件全名加人到ArrayList对象   
}
else
{
if (checkIsFile(dir + strRemote))
continue;
else
{
string strRemotes=strRemote + "/";
strLength = strRemotes.Length;
dir += strRemotes;
if (dirSub != null)
{
dirSub += strRemotes;
GetFiles(dirSub, ftpClient);
}
else
//if (strRemotes == comboProduct.SelectedText)
GetFiles(dir, ftpClient);
}
}
}
}
}
else
{
dirSub = dir.Substring(0, dir.Length - strLength);
}
}
}
//判断文件是否为空
private bool checkIsFile(string nodeText)
{
string ext = System.IO.Path.GetExtension(nodeText);

if (ext == "")
return false;
else
return true;
}
//搜索
private void ButtonSearch_Click(object sender, EventArgs e)
{
try
{
string ftpString = "/" + "allData/5/" + comboProduct.SelectedItem.ToString() + "/2013/";
this.GetFiles(ftpString, ftpClient);
string[] list = (string[])alst.ToArray(typeof(string));//把ArrayList转化为string[]  
ftpClient = null;
FormResult frm = new FormResult(list);
frm.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show("搜索错误.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//年月日转换
private string dataTimeToDays(string dateTimePicker)
{
string strTP = dateTimePicker;
char[] splits = new char[] {'年', '月', '日' };
string[] strTPs = strTP.Split(splits);
int days = Convert.ToInt32(strTPs[1]);
days *= 30;
int day = Convert.ToInt32(strTPs[2]);
day += days;
string reStr = strTPs[0] + day.ToString();
if (reStr.Length == 6)
{
reStr = reStr.Substring(5);
return strTPs[0] + "0" + reStr;
}
else if (reStr.Length == 5)
{
reStr = reStr.Substring(5);
return strTPs[0] + "00" + reStr;
}
else
return reStr;
}
//判断是否在选定时间间隔中
private bool checkTime(string nameTime, string dateTimePickerBegain, string dateTimePickerEnd)
{
string dateTimeBegain = dataTimeToDays(dateTimePickerBegain);
string dateTimeEnd = dataTimeToDays(dateTimePickerEnd);
if (Convert.ToInt32(nameTime) <= Convert.ToInt32(dateTimeEnd) && Convert.ToInt32(nameTime) >= Convert.ToInt32(dateTimeBegain))
return true;
else
return false;
}

实现远程FTP特定时间轨道号MODIS数据的搜索的更多相关文章

  1. Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本

    说明:  1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是 ...

  2. Linux下自动备份MySQL数据库并上传到远程FTP服务器

    Linux下自动备份MySQL数据库并上传到远程FTP服务器且删除指定日期前的备份Shell脚本 说明:  1.备份MySQL数据库存放目录/var/lib/mysql下面的xshelldata数据库 ...

  3. CentOS Linux自动备份MySQL数据库到远程FTP服务器并删除指定日期前的备份Shell脚本

    说明: 我这里要把MySQL数据库存放目录/var/lib/mysql下面的pw85数据库备份到/home/mysql_data里面,并且保存为mysqldata_bak_2011_11_03.tar ...

  4. 从exchange2010上面删除特定主题或特定时间的邮件

    昨天在上班的公交上接到同事电话,说他的的部门老大发错了一封邮件到另外一个同事邮箱了,问我能不 能去那个同事的邮箱里面删除,我一想,之前在网上看到过资料,到了公司趁那个误接收邮件的同事还没有来,在服务器 ...

  5. 发布站点到远程FTP根目录

    第一步:修改 phpcms/modules/admin/templates/site_add.tpl.php 找到 <legend><?php echo L('release_poi ...

  6. django apscheduler在特定时间执行一次任务(run at a specify time only once)

      如何使程序在特定时间只执行一次,我查了一下. celery可以,时间以秒计. task = mytask.apply_async(args=[10, 20], countdown=60) 不过,我 ...

  7. Centos下ftp协议连接远程ftp server主机

    环境说明 [root@Check3 ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@Check3 ~]# uname -a L ...

  8. Notepad++ 连接远程 FTP 进行文件编辑

    一.下载安装 Notepad++ 1.下载 Notepad++ : https://pan.baidu.com/s/1o7VrS4y 密码 : ck8a 2.安装 Notepad++ 2.1.勾选所有 ...

  9. linux自动备份文件和数据库并上传到指定的远程FTP中

    直接把以下脚本复制到/root/backup.sh[root@lvtao.net ~]# chmod +x /root/backup.sh[root@lvtao.net ~]# crontab -e0 ...

随机推荐

  1. CC_STACKPROTECTOR防内核堆栈溢出补丁分析【转】

    转自:https://yq.aliyun.com/articles/1723 摘要: 作者:王智通   CC_STACKPROTECT补丁是Tejun Heo在09年给主线kernel提交的一个用来防 ...

  2. mybatis,Spring等工具对xml文件正确性的验证

    我们知道mybatis或者spring都是使用xml文件作为配置文件,配置文件的格式都是定义在叫做.dtd或者.xsd文件中的,当工具在解析用户自己定义的xml文件的时候,如何才能知道用户自定义的文件 ...

  3. 【转】Android选项卡置底的方法

    转载地址:http://www.oschina.net/code/snippet_163910_6092 发现很多Android应用的选项卡 都是显示在页面底部的,网上有资料:通过反射获取TabWid ...

  4. 2016湖大校赛 L题 The Sequence likes Ladder

    题意:S1=a,Sn=a*(Sn-1)^k%m,且有(a,m)=1,给出i,求Si. 思路:首先我们可以写出Sn的通项a^(1+k+k^2+...k^n-1);其次注意到m的范围是10000以内,所以 ...

  5. webapi 通过dynamic 接收可变参数

    public class JsonParamModel { /// <summary> /// json key /// </summary> public string Js ...

  6. CentOS 安装 Dubbo 管理控制台

    安装之前需要安装zookeeper详情http://www.cnblogs.com/zuge/p/6141101.html Dubbo 管控台可以对注册到 zookeeper 注册中心的服务或服务消费 ...

  7. WebForm Repeater Response以及 地址栏

    Repeater重复器: Repeater中有五个模板,这里需要注意的是4个 <HeaderTemplate> - 开头,只执行一次的内容 <ItemTemplate> - 需 ...

  8. PHP性状的使用

    <?php trait Geocodable{ /** @var string */ protected $address; /** @var \Geocoder\Geocoder */ pro ...

  9. 内置函数callable(object)

    如果对象object参数是可以调用的对象,就返回True:否则返回False.不过要注意的是,当一个对象是可以调用的,并不表示调用该对象时执行一定成功,但不可调用的对象去调用时一定不会成功.如果类对象 ...

  10. 设计一个泛型类Collection

    要求:设计一个泛型类Collection,它存储object对象的集合(在数组中),以及该集合当前的大小.提供public方法isEmtpy,makeEmpty,insert,remove,isPre ...