一、FileZilla

Filezilla分为client和server。其中FileZilla Server是Windows平台下一个小巧的第三方FTP服务器软件,系统资源也占用非常小,可以让你快速简单的建立自己的FTP服务器。

打开FileZilla,进行如下操作

下图红色区域就是linux系统的文件目录,可以直接把windows下的文件直接拖拽进去。

二、WinSCP

跟FileZilla一样,也是一款十分方便的文件传输工具。WinSCP是连接Windows和Linux的。

WinSCP .NET Assembly and SFTP

https://winscp.net/eng/docs/library#csharp

// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "example.com",
UserName = "user",
Password = "mypassword",
SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
}; using (Session session = new Session())
{
// Connect
session.Open(sessionOptions); // Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary; TransferOperationResult transferResult;
transferResult = session.PutFiles(@"d:\toupload\*", "/home/user/", false, transferOptions); // Throw on any error
transferResult.Check(); // Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}

三、FluentFTP

FluentFTP是一款老外开发的基于.Net的支持FTP及的FTPS 的FTP类库,FluentFTP是完全托管的FTP客户端,被设计为易于使用和易于扩展。它支持文件和目录列表,上传和下载文件和SSL / TLS连接。

它底层由Socket实现,可以连接到Unix和Windows IIS建立FTP的服务器,

github:https://github.com/robinrodricks/FluentFTP

举例:

// create an FTP client
FtpClient client = new FtpClient("123.123.123.123"); // if you don't specify login credentials, we use the "anonymous" user account
client.Credentials = new NetworkCredential("david", "pass123"); // begin connecting to the server
client.Connect(); // get a list of files and directories in the "/htdocs" folder
foreach (FtpListItem item in client.GetListing("/htdocs")) { // if this is a file
if (item.Type == FtpFileSystemObjectType.File){ // get the file size
long size = client.GetFileSize(item.FullName); } // get modified date/time of the file or folder
DateTime time = client.GetModifiedTime(item.FullName); // calculate a hash for the file on the server side (default algorithm)
FtpHash hash = client.GetHash(item.FullName); } // upload a file
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt"); // rename the uploaded file
client.Rename("/htdocs/big.txt", "/htdocs/big2.txt"); // download the file again
client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/big2.txt"); // delete the file
client.DeleteFile("/htdocs/big2.txt"); // delete a folder recursively
client.DeleteDirectory("/htdocs/extras/"); // check if a file exists
if (client.FileExists("/htdocs/big2.txt")){ } // check if a folder exists
if (client.DirectoryExists("/htdocs/extras/")){ } // upload a file and retry 3 times before giving up
client.RetryAttempts = 3;
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/big.txt", FtpExists.Overwrite, false, FtpVerify.Retry); // disconnect! good bye!
client.Disconnect();

对FluentFTP部分操作封装类

public class FtpFileMetadata
{
public long FileLength { get; set; }
public string MD5Hash { get; set; }
public DateTime LastModifyTime { get; set; }
} public class FtpHelper
{
private FtpClient _client = null;
private string _host = "127.0.0.1";
private int _port = 21;
private string _username = "Anonymous";
private string _password = "";
private string _workingDirectory = "";
public string WorkingDirectory
{
get
{
return _workingDirectory;
}
}
public FtpHelper(string host, int port, string username, string password)
{
_host = host;
_port = port;
_username = username;
_password = password;
} public Stream GetStream(string remotePath)
{
Open();
return _client.OpenRead(remotePath);
} public void Get(string localPath, string remotePath)
{
Open();
_client.DownloadFile(localPath, remotePath, true);
} public void Upload(Stream s, string remotePath)
{
Open();
_client.Upload(s, remotePath, FtpExists.Overwrite, true);
} public void Upload(string localFile, string remotePath)
{
Open();
using (FileStream fileStream = new FileStream(localFile, FileMode.Open))
{
_client.Upload(fileStream, remotePath, FtpExists.Overwrite, true);
}
} public int UploadFiles(IEnumerable<string> localFiles, string remoteDir)
{
Open();
List<FileInfo> files = new List<FileInfo>();
foreach (var lf in localFiles)
{
files.Add(new FileInfo(lf));
}
int count = _client.UploadFiles(files, remoteDir, FtpExists.Overwrite, true, FtpVerify.Retry);
return count;
} public void MkDir(string dirName)
{
Open();
_client.CreateDirectory(dirName);
} public bool FileExists(string remotePath)
{
Open();
return _client.FileExists(remotePath);
}
public bool DirExists(string remoteDir)
{
Open();
return _client.DirectoryExists(remoteDir);
} public FtpListItem[] List(string remoteDir)
{
Open();
var f = _client.GetListing();
FtpListItem[] listItems = _client.GetListing(remoteDir);
return listItems;
} public FtpFileMetadata Metadata(string remotePath)
{
Open();
long size = _client.GetFileSize(remotePath);
DateTime lastModifyTime = _client.GetModifiedTime(remotePath); return new FtpFileMetadata()
{
FileLength = size,
LastModifyTime = lastModifyTime
};
} public bool TestConnection()
{
return _client.IsConnected;
} public void SetWorkingDirectory(string remoteBaseDir)
{
Open();
if (!DirExists(remoteBaseDir))
MkDir(remoteBaseDir);
_client.SetWorkingDirectory(remoteBaseDir);
_workingDirectory = remoteBaseDir;
}
private void Open()
{
if (_client == null)
{
_client = new FtpClient(_host, new System.Net.NetworkCredential(_username, _password));
_client.Port = 21;
_client.RetryAttempts = 3;
if (!string.IsNullOrWhiteSpace(_workingDirectory))
{
_client.SetWorkingDirectory(_workingDirectory);
}
}
}
}

FTP工具FileZilla&WinSCP与FTP类库FluentFTP的更多相关文章

  1. linuxMint下安装ftp工具--filezilla

    windows下ftp工具有好多,linux下推荐用filezilla 安装filezilla很简单,安装完后,使用方式和windows下面一样. 第一种方式: 直接去filezilla官网下载软件包 ...

  2. FTP工具-FileZilla安装使用教程

    1.首先,百度搜索“FileZilla”,进入官网,下载地址:https://www.filezilla.cn/download/client  ,根据自己电脑配置去下载 2.下载本地,双击运行安装程 ...

  3. Mac 10.12安装FTP工具FileZilla

    说明:在Windows估计用的比较多,在Linux基本不用了,CRT和Xshell基本可以完成上传. 下载: (链接: https://pan.baidu.com/s/1bpaxmeN 密码: uuw ...

  4. Mac / Windows 下的 FTP 工具filezilla

    https://filezilla-project.org/download.php?platform=osx

  5. Serv-U设置被动模式(FTP工具)

    FTP服务器在公司内网,通过端口映射把21端口映射出去. 公司一些机器也在各个省的机房内网.好在这些机器可以访问公网.由于各个地区的机器托管在各个地区机房. 我有公司防火墙的权限,可以做防火墙上做端口 ...

  6. 远程登录工具 —— filezilla(FTP vs. SFTP)、xshell、secureCRT

    filezilla:是一个免费开源的 FTP 软件,分为客户端版本和服务器版本,具备所有的 FTP 软件功能. 支持的协议:FTP & SFTP(Secure File Transfer Pr ...

  7. window环境下使用filezilla server搭建ftp服务器

    前言 在做项目的时候,需要提供ftp服务,开始的时候使用微软自动的iss上的ftp服务,一段时间后发现无法自定义用户,只能使用系统的用户,使用起来很不方便,在权限管理方面也是不太好.所以换用了file ...

  8. Java操作FTP工具类(实例详解)

    这里使用Apache的FTP jar 包 没有使用Java自带的FTPjar包  工具类 package com.zit.ftp; import java.io.File; import java.i ...

  9. c#FTP应用---FileZilla Server

    一.下载Filezilla  Server 官网网址:https://filezilla-project.org FileZilla Server是目前稍有的免费FTP服务器软件,比起Serv-U F ...

随机推荐

  1. [codeup] 1943 进制转换

    题目描述 将一个长度最多为30位数字的十进制非负整数转换为二进制数输出. 输入 多组数据,每行为一个长度不超过30位的十进制非负整数.(注意是10进制数字的个数可能有30个,而非30bits的整数) ...

  2. HTML的map-area的使用

    使用背景 在把设置图转成页面的时候,时常会遇到这种情况:一张小图片上有好多个可以点击的小图标,按常规的处理方法是把这一个一个的小图切出来,然后每个加个a标签进行跳转,但是这样会非常的浪费时间,而且会增 ...

  3. BG.Hive - part3

    1. Hive数据导入 - Load Load,加载,不会进行任何数据转换和处理的操作,只会进行数据Move操作,将元数据移动到HDFS指定目录 a> hdfs dfs -put 'hdfs的h ...

  4. ABP学习入门系列(四)(创建Service)

    一,一些相关解释 Service 在应用服务层也就是application层.应用服务用于将领域(业务)逻辑暴露给展现层.展现层通过传入DTO(数据传输对象)参数来调用应用服务,而应用服务通过领域对象 ...

  5. [日常] nginx与负载均衡

    去年的事,随便记记 ========================================================================= 2017年3月31日 记录: n ...

  6. MySQL4:索引

    什么是索引 索引是对数据库表中一列或者多列的值进行排序的一种结构,所引用于快速找出在某个 列中有一特定值的行.不使用索引,MySQL必须从第一条记录开始读完整个表,直到找出相关的行.表越大,查询数据所 ...

  7. “使用IDEA,配置文件是yml,无法获取[环境变量],值是null”的问题处理

    为了便于隐藏用户名和密码,我们有时会用到“环境变量”. Spring Boot提供了很好的机制,可以在配置文件中,如application.yml书写以下格式,然后在代码中@Value就可以获取“环境 ...

  8. python中深浅拷贝

    python的复制,深拷贝和浅拷贝的区别   在python中,对象赋值实际上是对象的引用.当创建一个对象,然后把它赋给另一个变量的时候,python并没有拷贝这个对象,而只是拷贝了这个对象的引用 一 ...

  9. H5学习入门

    [块级标签与行级标签的区别] 1.块级标签: 默认宽度100%(独占一行) 自动换行(右边不能有任何东西) 可以使用css设置宽度高度   2.行级标签: 内容宽度,由内容撑开(内容多宽,宽度就占多宽 ...

  10. 导出PDF乱码

     客户问题: 客户环境 LINUX系统weblogic10.3.0.0 用weblogic自带 JDK160_05 导出PDF中文字体全是口 解决方法: 客户的说他们的测试服务器和生产服务器环境是 ...