资源简介
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个文件信息
- 上一篇:实验一 绘图类及其对象程序设计
- 下一篇:反猜数字程序计算机猜你心里想的数字
相关资源
- zkjxa8.docx
- Verilog的135个经典设计.rar
- netcat-1.10_redhat_x86_64.zip
- Symantec_BackupExec2012.7z
- 游戏盾源码.rar
- nokia.rar
- msnildsl_9664769.zip
- IntrotoSecISM.pdf
- opencv分类器.rar
- labviewmyrio2017地址.txt
- bd6c83ef89bd4112bb878cfb80a22251.zip
- b+树查找的实现原代码.doc
- 百度云下载链接.txt112990
- dubbo.txt
- 657088微擎开发笔记.docx
- Multisim14.0系统数据库.rar
- WAS_IHS_9完整安装包.txt
- Magicv蓝屏修正完美破解补丁.rar
- 5000本epub书籍有目录.txt
- FarPoint.Win.Spread4.0注册机.zip
- 粒子群优化粒子滤波方法
- 统计图.rp
- reGeorg-master.zip
- 自定义控件.txt
- 刷客——至善网刷课软件.rar
- caodv.zip
- haarcascade_frontalface_default.rar
- Sbus.rar
- TOOL0006V3600cracked.zip
- voc.txt
评论
共有 条评论