FTP Client
1: /// <summary>2: /// FTP 管理类3: /// </summary>4: public class FTPManage5: {6: private string _Host; //服务器地址7: private int? _Port; //端口号8: private string _User; //用户名9: private string _Pass; //密码10: //public string Path; //具体文件路径11: //public string fileName; //具体下载文件12: //public string SaveFilePath; //保存路径13:14: /// <summary>15: /// 构造函数16: /// </summary>17: /// <param name="Host"></param>18: /// <param name="Port"></param>19: /// <param name="User"></param>20: /// <param name="Pass"></param>21: public FTPManage(string Host, int? Port, string User, string Pass)22: {23: this._Host = Host;24: this._Port = Port;25: this._User = User;26: this._Pass = Pass;27: }28:29: /// <summary>30: /// 判断文件是否存在31: /// </summary>32: /// <returns></returns>33: public string ChkIsFile(string path, string fielName)34: {35: string defaultStr = string.Empty; //默认不存在36: if (string.IsNullOrEmpty(fielName)) //必须填写文件名37: {38: return defaultStr = "文件名不能为空";39: }40: string url = string.Format("ftp://{0}/{1}/{2}", _Host, path, fielName);41: var request = (FtpWebRequest)WebRequest.Create(url);42: request.Credentials = new NetworkCredential(_User, _Pass);43: request.Method = WebRequestMethods.Ftp.GetFileSize;44: try45: {46: FtpWebResponse response = (FtpWebResponse)request.GetResponse();47: }48: catch (WebException ex)49: {50: FtpWebResponse response = (FtpWebResponse)ex.Response;51: if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)52: {53:54: }55: return defaultStr = "获取文件异常";56: }57: return defaultStr;58: }59:60: /// <summary>61: /// 下载文件62: /// </summary>63: /// <param name="path"></param>64: /// <param name="file"></param>65: /// <param name="SavePath"></param>66: /// <returns></returns>67: public string LodeFile(string path, string fielName, string SavePath)68: {69: string defaultStr = string.Empty;70: if (string.IsNullOrEmpty(fielName)) //必须填写文件名71: {72: return defaultStr = "文件名不能为空";73: }74: if (string.IsNullOrEmpty(SavePath)) //必须填写文件名75: {76: return defaultStr = "文件保存路径不能为空";77: }78: try79: {80: string url = string.Format("ftp://{0}/{1}/{2}", _Host, path, fielName);81: FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(url);82: reqFTP.UseBinary = true;83: reqFTP.Credentials = new NetworkCredential(_User, _Pass);84:85: FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();86: Stream ftpStream = response.GetResponseStream();87: long cl = response.ContentLength;88: int bufferSize = 2048;89: int readCount;90: byte[] buffer = new byte[bufferSize];91:92: readCount = ftpStream.Read(buffer, 0, bufferSize);93: FileHelper.IsDirectory(SavePath);94: FileStream outputStream = new FileStream(SavePath + "\\" + fielName, FileMode.Create);95: while (readCount > 0)96: {97: outputStream.Write(buffer, 0, readCount);98: readCount = ftpStream.Read(buffer, 0, bufferSize);99: }100: ftpStream.Close();101: outputStream.Close();102: response.Close();103: }104: catch (Exception ex)105: {106: defaultStr = "文件下载异常:" + ex.Message;107: }108: return defaultStr;109: }110:111: /// <summary>112: /// 获取指定目录文件列表113: /// </summary>114: /// <returns></returns>115: public string[] GetFileList(string Path)116: {117: try118: {119: string url = string.Format("ftp://{0}/{1}", _Host, Path);120: //获得FTP文件上的文件列表121: FtpWebRequest request = (FtpWebRequest)WebRequest.Create(url);122: request.Method = WebRequestMethods.Ftp.ListDirectory;123: request.Credentials = new NetworkCredential(_User, _Pass);124:125: FtpWebResponse response = (FtpWebResponse)request.GetResponse();126: Stream stream = response.GetResponseStream();127:128: StreamReader reader = new StreamReader(stream);129: List<string> files = new List<string>();130:131: while (!reader.EndOfStream)132: {133: string file = reader.ReadLine();134: files.Add(file);135: }136:137: reader.Close();138: stream.Close();139:140: return files.ToArray();141: }142: catch { return new string[0]; }143: }144:145: }
FTP Client的更多相关文章
- Ubuntu Filezilla FTP Client 安装
/************************************************************************************* * Ubuntu File ...
- 使用 FileZilla FTP Client连接Vsftpd在执行LIST命令后提示连接超时
使用 FileZilla FTP Client 连接 Vsftpd在执行LIST命令后提示连接超时. vi /etc/vsftpd/vsftpd.conf 添加: #开启被动模式 pasv_enabl ...
- csharp: FTP Client Library using System.Net.FtpWebRequest
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- C# Ftp Client 基本操作
C# Ftp Client 上传.下载与删除 简单介绍一下Ftp Client 上传.下载与删除,这是目前比较常用的命令,各个方法其实都差不多,重点是了解Ftp命令协议. 1.建立连接 public ...
- FileZilla FTP Client
FileZilla Client是一个快速.实用.多功能和界面直观的免费的FTP客户端,虽然它是免费软件,可功能却一点也不含糊,比起那些共享软件来有过之而无不及,在新的版本中作者改进了手动下载的界面和 ...
- csharp: FTP Client Library using System.Net.FtpClient and FluentFTP,测试中存在的BUG修正
https://netftp.codeplex.com/ /// <summary> /// Gets a file listing from the server. Each FtpLi ...
- csharp:FTP Client Library using FtpWebRequest or Sockets
https://netftp.codeplex.com/SourceControl/latest http://ftplib.codeplex.com/ https://www.codeproject ...
- 【FileZilla FTP Client】文件与服务器操作客户端
跨平台的FTP,FTPS和SFTP客户端 可以断点续传进行上传.下载(需要服务器支持). 自定义命令. 可进行站点管理.
- Spring Boot Ftp Client 客户端示例支持断点续传
本章介绍 Spring Boot 整合 Ftpclient 的示例,支持断点续传 本项目源码下载 1 新建 Spring Boot Maven 示例工程项目 注意:是用来 IDEA 开发工具 File ...
随机推荐
- ashx实现文件下载以及文件MD5码测试
cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System ...
- 压位加速-poj-2443-Set Operation
题目链接: http://poj.org/problem?id=2443 题目意思: 有n个集合(n<=1000),每个集合有m个数ai(m<=10000,1=<ai<=100 ...
- 利用JConsole工具监控java程序内存和JVM
一.找到java应用程序对应的进程PI 性能测试应用程序访问地址:http://192.168.29.218:7070/training/ 部署的应用服务器为tomcat6.028 启动tomcat服 ...
- JavaScript 函数基础
1. JavaScript 函数基础 1. 定义方法 2. 函数的调用方法 3. 函数方法 apply : 将函数作为数组的方法来调用 将参数以数组形式传递给该方法 call : 将函数作为对象的 ...
- Enabling Active Directory Authentication for VMWare Server running on Linux《转载》
Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breid ...
- SpringTest2
Spring 框架第二天 AOP切面编程 今天重点内容: 1. 什么是AOP ? AOP实现原理是怎样的? AOP相关术语 2. AOP底层实现 (了解) ----- JDK动态代理. Cglib动态 ...
- Ubuntu中设置静态IP和DNS(转载)
原文地址:http://blog.sina.com.cn/s/blog_669421480102v3bb.html VMware 中使用网络,对虚拟机设置静态IP:在Ubuntu中设置静态IP共两步: ...
- jquery选择指定元素之外的所有元素
最近的项目中有这么一个需求,点击一排图片中的任意一张后底部弹出一个对话框,要求点击任意地方隐藏对话框 这个时候用not()显然是不现实的,用closest()可以实现差不多的功能 <!DOCTY ...
- 利用“参数赋值”防范SQL注入漏洞攻击
<<年轻,无权享受>————送给每一个看到此文的同僚们 在这无精打采的炎夏 我躺在阳台上房东的旧沙发 回想几个月来遇到的问题 我不禁内心开始慌张喘着粗气 还有大把时间去打拼 没有到只 ...
- Linux设置日期
$ date -s "2016-07-13 14:54" 把时间设置为2016-07-13 14:54