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. Java 序列化Serializable详解

    Java 序列化Serializable详解(附详细例子) Java 序列化Serializable详解(附详细例子) 1.什么是序列化和反序列化Serialization(序列化)是一种将对象以一连 ...

  2. php就业网版本已改版成功

    php就业网简介:www.php91.net,专注于Thinkphp框架教程的php框架学习中心.同时也有小崔老师自学php的教程,与你一起成长哦 同时,php就业网教程部分:http://www.p ...

  3. 【转载】Log4j详细使用教程

    本文由林炳文Evankaka创作,出处http://blog.csdn.net/evankaka 日志是应用软件中不可缺少的部分,Apache的开源项目Log4j是一个功能强大的日志组件,提供方便的日 ...

  4. centos 更换 yum源

    阿里云Linux安装镜像源地址:http://mirrors.aliyun.com/ CentOS系统更换软件安装源第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.repos ...

  5. HTML5:web socket 和 web worker

    a:hover { cursor: pointer } 做练习遇到了一个选择题,是关于web worker的,问web worker会不会影响页面性能?补习功课之后,答案是不会影响. 查阅了相关资料学 ...

  6. Unbuntu下使用SVN

    一.查看SVN版本 svn --version 二.查看SVN仓库 # 查看被svn仓库占用的所有端口 netstat -anp |grep svn # 查看所有端口对应的仓库 ps -ef | gr ...

  7. PHP: 深入pack/unpack

    https://my.oschina.net/goal/blog/195749 PHP作为一门为web而生的服务器端开发语言,被越来越多的公司所采用.其中不乏大公司,如腾迅.盛大.淘米.新浪等.在对性 ...

  8. Sublime Text 3 个人开发习惯

    1.添加author.date到函数注释里面 docblockr插件 a.preferences--package settings--docblockr--settings-user点击打开 b.在 ...

  9. T-SQL编程 —— 用户自定义函数(标量函数)

    用户自定义函数 在使用SQL server的时候,除了其内置的函数之外,还允许用户根据需要自己定义函数.根据用户定义函数返回值的类型,可以将用户定义的函数分为三个类别: 返回值为可更新表的函数 如果用 ...

  10. 两个平行div之间有间隙

    两个平行的div使用 display: inline-block 会导致元素之间有空隙解决方法: 父元素设置 font-size: 0;