实现远程FTP特定时间轨道号MODIS数据的搜索
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数据的搜索的更多相关文章
- Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本
说明: 1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是 ...
- Linux下自动备份MySQL数据库并上传到远程FTP服务器
Linux下自动备份MySQL数据库并上传到远程FTP服务器且删除指定日期前的备份Shell脚本 说明: 1.备份MySQL数据库存放目录/var/lib/mysql下面的xshelldata数据库 ...
- CentOS Linux自动备份MySQL数据库到远程FTP服务器并删除指定日期前的备份Shell脚本
说明: 我这里要把MySQL数据库存放目录/var/lib/mysql下面的pw85数据库备份到/home/mysql_data里面,并且保存为mysqldata_bak_2011_11_03.tar ...
- 从exchange2010上面删除特定主题或特定时间的邮件
昨天在上班的公交上接到同事电话,说他的的部门老大发错了一封邮件到另外一个同事邮箱了,问我能不 能去那个同事的邮箱里面删除,我一想,之前在网上看到过资料,到了公司趁那个误接收邮件的同事还没有来,在服务器 ...
- 发布站点到远程FTP根目录
第一步:修改 phpcms/modules/admin/templates/site_add.tpl.php 找到 <legend><?php echo L('release_poi ...
- django apscheduler在特定时间执行一次任务(run at a specify time only once)
如何使程序在特定时间只执行一次,我查了一下. celery可以,时间以秒计. task = mytask.apply_async(args=[10, 20], countdown=60) 不过,我 ...
- Centos下ftp协议连接远程ftp server主机
环境说明 [root@Check3 ~]# cat /etc/redhat-release CentOS release 6.9 (Final) [root@Check3 ~]# uname -a L ...
- Notepad++ 连接远程 FTP 进行文件编辑
一.下载安装 Notepad++ 1.下载 Notepad++ : https://pan.baidu.com/s/1o7VrS4y 密码 : ck8a 2.安装 Notepad++ 2.1.勾选所有 ...
- linux自动备份文件和数据库并上传到指定的远程FTP中
直接把以下脚本复制到/root/backup.sh[root@lvtao.net ~]# chmod +x /root/backup.sh[root@lvtao.net ~]# crontab -e0 ...
随机推荐
- 史上最详cxf-Springmvc-maven实现webservice教程(转)
虽知道webservice,工作两年一直没使用过,最近不忙趁机研究了下,实现了简单的服务端及客户端调用.鉴于慕课网没有webservice的教程,大多又都是学生,就在这里跟大家分享下,内容比较详细.大 ...
- js 获取url参数的值
//获取url参数函数function GetQueryString(name){ var reg = new RegExp("(^|&)"+ name +" ...
- vueJs+webpack单页面应用--vue-router配置
vue-route版本要跟vue版本同步,我的vue用的2.0+的,vue-router 也用了最新版2.1+ npm安装vue-router: $ npm install vue-router -- ...
- 使用ajax分页
前台页面: <table class="table table-hover"> <thead> <tr> <th class='hidde ...
- 回归分析法&一元线性回归操作和解释
用Excel做回归分析的详细步骤 一.什么是回归分析法 "回归分析"是解析"注目变量"和"因于变量"并明确两者关系的统计方法.此时,我们把因 ...
- Python3基础 创建一个空列表,一个空元组
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- 解决file_get_contents遇到中文文件名无法打开问题
利用file_get_contents打开文件或采集远程服务器文件如果文名或url中碰到汉字中文那么会出现failed to open stream:Lnvalid argument in错误. ...
- c# base和this关键字总结
base:用于在派生类中实现对基类公有或者受保护成员的访问,但是只局限在构造函数.实例方法和实例属性访问器中.MSDN中小结的具体功能包括: (1)调用基类上已被其他方法重写的方法. ( ...
- ucos中的三种临界区管理机制
熟悉ucos,或者读过Jean.J.Labrosse写过的ucos书籍的人,一定会知道ucos中著名的临界区管理宏:OS_ENTER_CRITICAL()和OS_EXIT_CRITICAL(). 同样 ...
- Java Web之会话管理二:Session
一.Session 在web开发中,服务器可以为每个yoghurt浏览器创建一个会话对象(Session)对象.注意:一个浏览器独占一个Session对象.因此,在需要保存用户数据时,服务器程序可以把 ...