资源简介
MyWatch.zip

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
namespace MyWatch
{
static public class FtpHelper
{
//基本设置
static private string path = @“ftp://“ + ConfigurationManager.AppSettings[“ServerIp“] + “/“; //目标路径
static private string ftpip = ConfigurationManager.AppSettings[“ServerIp“]; //ftp IP地址
static private string username = ConfigurationManager.AppSettings[“Username“];//ftp用户名
static private string password = ConfigurationManager.AppSettings[“Password“];//ftp密码
//获取ftp上面的文件和文件夹
public static string[] GetFileList(string dir)
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest request;
try
{
request = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
request.UseBinary = true;
request.Credentials = new NetworkCredential(username password);//设置用户名和密码
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.UseBinary = true;
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append(“\n“);
Console.WriteLine(line);
line = reader.ReadLine();
}
// to remove the trailing ‘\n‘
result.Remove(result.ToString().LastIndexOf(‘\n‘) 1);
reader.Close();
response.Close();
return result.ToString().Split(‘\n‘);
}
catch (Exception ex)
{
Console.WriteLine(“获取ftp上面的文件和文件夹:“ + ex.Message);
downloadFiles = null;
return downloadFiles;
}
}
///
/// 获取文件大小
///
/// ip服务器下的相对路径
/// 文件大小
public static int GetFileSize(string file)
{
StringBuilder result = new StringBuilder();
FtpWebRequest request;
try
{
request = (FtpWebRequest)FtpWebRequest.Create(new Uri(path + file));
request.UseBinary = true;
request.Credentials = new NetworkCredential(username password);//设置用户名和密码
request.Method = WebRequestMethods.Ftp.GetFileSize;
int dataLength = (int)request.GetResponse().ContentLength;
return dataLength;
}
catch (Exception ex)
{
Console.Write
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-01-15 11:12 MyWatch\
目录 0 2015-01-15 10:06 MyWatch\MyWatch\
文件 1543 2015-01-15 11:13 MyWatch\MyWatch.sln
文件 36352 2015-01-15 12:29 MyWatch\MyWatch.suo
文件 673 2015-01-15 12:21 MyWatch\MyWatch\App.config
目录 0 2015-01-14 15:08 MyWatch\MyWatch\bin\
目录 0 2015-01-15 11:38 MyWatch\MyWatch\bin\Debug\
文件 18432 2015-01-15 11:37 MyWatch\MyWatch\bin\Debug\MyWatch.exe
文件 662 2015-01-15 11:38 MyWatch\MyWatch\bin\Debug\MyWatch.exe.Config
文件 40448 2015-01-15 11:37 MyWatch\MyWatch\bin\Debug\MyWatch.pdb
文件 11600 2015-01-15 11:38 MyWatch\MyWatch\bin\Debug\MyWatch.vshost.exe
文件 664 2015-01-15 11:35 MyWatch\MyWatch\bin\Debug\MyWatch.vshost.exe.config
目录 0 2015-01-14 15:08 MyWatch\MyWatch\bin\Release\
文件 11777 2015-01-15 10:39 MyWatch\MyWatch\FtpHelper.cs
文件 7730 2015-01-15 12:27 MyWatch\MyWatch\MyForm.cs
文件 9008 2015-01-15 11:18 MyWatch\MyWatch\MyForm.Designer.cs
文件 5817 2015-01-15 11:18 MyWatch\MyWatch\MyForm.resx
文件 3953 2015-01-15 10:07 MyWatch\MyWatch\MyWatch.csproj
目录 0 2015-01-14 14:51 MyWatch\MyWatch\obj\
目录 0 2015-01-14 14:51 MyWatch\MyWatch\obj\x86\
目录 0 2015-01-15 11:37 MyWatch\MyWatch\obj\x86\Debug\
文件 5359 2015-01-14 15:34 MyWatch\MyWatch\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6655 2015-01-15 11:37 MyWatch\MyWatch\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 597 2015-01-15 11:38 MyWatch\MyWatch\obj\x86\Debug\MyWatch.csproj.FileListAbsolute.txt
文件 976 2015-01-15 11:28 MyWatch\MyWatch\obj\x86\Debug\MyWatch.csproj.GenerateResource.Cache
文件 18432 2015-01-15 11:37 MyWatch\MyWatch\obj\x86\Debug\MyWatch.exe
文件 180 2015-01-15 11:28 MyWatch\MyWatch\obj\x86\Debug\MyWatch.MyForm.resources
文件 40448 2015-01-15 11:37 MyWatch\MyWatch\obj\x86\Debug\MyWatch.pdb
文件 180 2015-01-15 10:20 MyWatch\MyWatch\obj\x86\Debug\MyWatch.Properties.Resources.resources
目录 0 2015-01-15 10:08 MyWatch\MyWatch\obj\x86\Debug\TempPE\
文件 489 2015-01-14 14:56 MyWatch\MyWatch\Program.cs
............此处省略6个文件信息
- 上一篇:实验一 绘图类及其对象程序设计
- 下一篇:反猜数字程序计算机猜你心里想的数字
相关资源
- PID_AutoTune_v0.rar
- vspd7.2.308.zip
- 价值2k的H漫画小说系统
- Pythonamp;课堂amp;笔记(高淇amp;400;集第
- ddos压力测试工具99657
- UML建模大全
- 开源1A锂电池充电板TP4056原理图+PCB
- m1卡 ic卡可选择扇区初始化加密软件
- TSCC.exe
- FTP课程设计(服务端+客户端)
- 计算机图形学 边填充算法实现代码
- 电力系统潮流计算程序集合
- oracle数据迁移项目实施方案
- Web Api 通过文件流 文件到本地
- Visio图标-最新最全的网络通信图标库
- Spire API文档
- OpenGL参考手册
- Python中Numpy库最新教程
- SPD博士V5.3.exe
- 直流无刷电机方波驱动 stm32 例程代码
- layui后台管理模板
- 仿知乎界面小程序源代码
- 云平台-阿里云详细介绍
- photoshop经典1000例
- scratch垃圾分类源码(最终版本).sb
- IAR ARM 7.8破解
- TI CCS V5.4 安装步骤及破解文件
- 松下plc FP-XH的驱动
- 局域网硬件信息收集工具
- 加快Windows XP操作系统开机速度
评论
共有 条评论