实现远程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 ...
随机推荐
- Linux-4.4-x86_64 内核配置选项简介【转】
转自:http://fx114.net/qa-188-150553.aspx 本篇文章主要介绍了"Linux-4.4-x86_64 内核配置选项简介",主要涉及到Linux-4.4 ...
- 初始python第三天(三)
全局变量与局部变量 1.什么是全局变量 在globals中的变量,都是全局变量,全局变量的作用域就是整个程序 NAME = 'alex' def global_test(): name = 'alex ...
- Bash:-:-定义空变量作为输出结合换行符\n和column输出
RET="" declare -a HOST=() declare -a ALL_SVR=() declare -a FREESVR=() ;i<${#_ALL_AGENT_ ...
- mysql登陆问题
1.centos6下mysql5.7的登陆问题 问题的描述:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using p ...
- Thinkphp框架回顾(三)之怎么实现平常的sql操作数据库
1.首先简单介绍一下我们的数据库,thinkphp数据库下有一个tp_user表,然后有四个字段....id,username,password,sex 我们今天的任务就是在Thinkphp下将数据调 ...
- [Dynamic Language] 用Sphinx自动生成python代码注释文档
用Sphinx自动生成python代码注释文档 pip install -U sphinx 安装好了之后,对Python代码的文档,一般使用sphinx-apidoc来自动生成:查看帮助mac-abe ...
- Java SE 基础:注释
Java SE 基础:注释 一.注释定义 用于解释说明程序的文字. 二.注释的作用 1.解释说明程序,提高程序的可读性 2.可以帮助我们调试程序:通过注释代码块,检测错误位置 三.格式 1.单行注释 ...
- Web Performance Test : 为Request的Post参数名添加XPath支持
问题描述 本文的标题看起来有些含糊其辞,这里我需要把问题阐述得更加清楚.这是我们使用VSTS进行Web Performance Test时,Asp.net造成的特定问题(也许其他开发工具或插件也会造成 ...
- 集群节点间网络通信TIPC
1. TIPC背景介绍 TIPC主要是用于集群网络环境之中,它这个协议有一些前提假设包括: 协议发送的大部分message都是直接到达目的地(无路由): message的传输时间都很短; messag ...
- ShareSDK 集成 Google+ 登录 400. Error:redirect_uri_mismatch 和 Error Domain=ShareSDKErrorDomain Code=204
最近在集成ShareSDK中 Google+ 登录授权时候 出现了如下几个问题 1. 400. Error:redirect_uri_mismatch 出现这种情况, redirectUri应 ...