C# FTPHelper工具类
/// <summary>
/// Ftp
/// </summary>
public class FtpFileOperation
{
private string _ftpIp;
private string _ftpUser;
private string _ftpPassword;
private FtpWebRequest _ftpWebRequest; public FtpFileOperation(string ftpIp, string ftpUser, string ftpPassword)
{
_ftpIp = ftpIp;
_ftpUser = ftpUser;
_ftpPassword = ftpPassword;
} /// <summary>
/// Connect
/// </summary>
/// <param name="ftpUrl"></param>
/// <returns></returns>
public bool Connect(string ftpUrl)
{
try
{
_ftpWebRequest = (FtpWebRequest)FtpWebRequest.Create(ftpUrl);
_ftpWebRequest.UseBinary = true;
_ftpWebRequest.Credentials = new NetworkCredential(_ftpUser, _ftpPassword);
return true;
}
catch (Exception ex)
{
Logger.Error(ex);
return false;
}
} /// <summary>
/// Download
/// </summary>
/// <param name="ftpFilePath"></param>
/// <param name="savePath"></param>
/// <returns></returns>
public bool Download(string ftpFilePath,string savePath)
{
try
{
if (Connect(String.Format("ftp://{0}/{1}", _ftpIp, ftpFilePath)))
{
FtpWebResponse ftpResponse = (FtpWebResponse)_ftpWebRequest.GetResponse();
Stream ftpStream = ftpResponse.GetResponseStream();
byte[] buffer = new byte[];
int readCount = ;
FileStream outputStream = new FileStream(savePath, FileMode.Create);
readCount = ftpStream.Read(buffer, , buffer.Length);
while(readCount > )
{
outputStream.Write(buffer, , readCount);
readCount = ftpStream.Read(buffer, , buffer.Length);
}
ftpStream.Close();
outputStream.Close();
ftpResponse.Close();
return true;
}
}
catch (Exception ex)
{
Logger.Error(ex);
}
return false;
}
}
C# FTPHelper工具类的更多相关文章
- 【转载】C#工具类:FTP操作辅助类FTPHelper
FTP是一个8位的客户端-服务器协议,能操作任何类型的文件而不需要进一步处理,就像MIME或Unicode一样.可以通过C#中的FtpWebRequest类.NetworkCredential类.We ...
- Java基础Map接口+Collections工具类
1.Map中我们主要讲两个接口 HashMap 与 LinkedHashMap (1)其中LinkedHashMap是有序的 怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...
- Android—关于自定义对话框的工具类
开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...
- [转]Java常用工具类集合
转自:http://blog.csdn.net/justdb/article/details/8653166 数据库连接工具类——仅仅获得连接对象 ConnDB.java package com.ut ...
- js常用工具类.
一些js的工具类 复制代码 /** * Created by sevennight on 15-1-31. * js常用工具类 */ /** * 方法作用:[格式化时间] * 使用方法 * 示例: * ...
- Guava库介绍之实用工具类
作者:Jack47 转载请保留作者和原文出处 欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. 本文是我写的Google开源的Java编程库Guava系列之一,主要介 ...
- Java程序员的日常—— Arrays工具类的使用
这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...
- .net使用正则表达式校验、匹配字符工具类
开发程序离不开数据的校验,这里整理了一些数据的校验.匹配的方法: /// <summary> /// 字符(串)验证.匹配工具类 /// </summary> public c ...
- WebUtils-网络请求工具类
网络请求工具类,大幅代码借鉴aplipay. using System; using System.Collections.Generic; using System.IO; using System ...
随机推荐
- poj1723 SOLDIERS
soldiers真乃神题也! 行列显然可以分开处理. 行好办,显然就是一个货仓选址问题,取中位数即可. 列呢?? ?????? 因为懒得推式子,用不了二分,我决定使用枚举大法!一算复杂度O(n^2), ...
- Ubuntu下安装Goldendict(翻译软件)
Ubuntu直接安装 sudo apt-get install goldendict 通过源码安装 失败 下载词典 http://blog.sina.com.cn/s/blog_c58823b3010 ...
- appium 切换native/ webview,findby,还有页面元素定位一直小于0的问题的解决
之前一直有个bug没有解决. 今天,终于解决了. 疑问过程: app是混合应用,项目做了H5优化之后,以前的用例执行总会失败,体现在原来的一个元素点击无反馈 排查原因:1.项目做了H5优化,2.测试的 ...
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:co
在pom中加入下面代码: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId&g ...
- Session兑现的一级缓存
快照机制:
- 数据挖掘的标准流程-CRISP-DM
1.起源 CRISP-DM (cross-industry standard process for data mining), 即为"跨行业数据挖掘过程标准".此KDD(know ...
- Linux报错
Linux报错 ------------------- 在VMware虚拟机中配置yum源时,执行 mount /dev/cdrom /mnt/cdrom 出现 mount: no medium fo ...
- jmeter奇淫妙计之遍历sql多列结果集
foreach控制器加${__V()}函数和${__counter(TRUE,)}函数 处理sql多列结果的遍历真的是绝配啊,之前一直用循环控制器+count函数,或者while控制器加count函数 ...
- gometalinter代码质量检查分析工具(golang)
GitHub地址:https://github.com/alecthomas/gometalinter gometalinter安装和使用 1.安装 go get github.com/alectho ...
- chrome截图全网页
1.F12 2.ctrl+shift+p 3.输入:capture 4.选择Capture full size screenshot