本文整理汇总了C#中FtpClient类的典型用法代码示例。如果您正苦于以下问题:C# FtpClient类的具体用法?C# FtpClient怎么用?C# FtpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FtpClient类属于命名空间,在下文中一共展示了FtpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SetWorkingDirectory
public static void SetWorkingDirectory() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.SetWorkingDirectory("/full/or/relative/path");
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:7,代码来源:SetWorkingDirectory.cs
示例2: CreateDirectory
public static void CreateDirectory() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.CreateDirectory("/test/path/that/should/be/created", true);
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:7,代码来源:CreateDirectory.cs
示例3: DeleteFile
public static void DeleteFile() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.DeleteFile("/full/or/relative/path/to/file");
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:7,代码来源:DeleteFile.cs
示例4: Main
static void Main(string[] args)
{
//args = new[] {@"c:\Users\Pz\Documents\dev\praettest.cfg"};
args = new[] {@"c:\Users\Pz\Documents\dev\sync.cfg"};
var configuration = ParseArgs(args);
if (configuration == null)
{
PrintUsage();
}
else
{
var trackedFilesPath = args[0];
try
{
var ftp = new FtpClient(trackedFilesPath, configuration);
ftp.Synchronize();
}
catch (Exception e)
{
if (!FtpClient.Handle(e)) throw;
}
}
Console.WriteLine("");
Console.WriteLine("Press any key to quit...");
Console.ReadKey();
}
开发者ID:martin-cech,项目名称:ftpsync,代码行数:30,代码来源:Program.cs
示例5: Main
private static void Main(string[] args)
{
string hostAddress;
string username;
string password;
Console.WriteLine("Reading login data...");
/*
* Read the login data for the server from a text-file called "Login",
* with the following structure:
*
* Server address
* Username
* Password
*
*/
var loginData = File.ReadAllLines("Login");
hostAddress = loginData[0];
username = loginData[1];
password = loginData[2];
Console.WriteLine("Starting integration test...");
Console.WriteLine();
client = new FtpClient(new NetworkCredential(username, password));
CreateDirectoryTest(new Uri(new Uri(hostAddress), "/TestDirectory1"));
DeleteDirectoryTest(new Uri(new Uri(hostAddress), "/TestDirectory1"));
Console.WriteLine();
Console.WriteLine("Integration test finished.");
Console.ReadLine();
}
开发者ID:eric-seekas,项目名称:FlagFtp,代码行数:35,代码来源:Tests.cs
示例6: UploadFile
public static void UploadFile(string ftpHost, string username, string password, string filepathToUpload, string fileToWrite)
{
FtpClient chipbox = new FtpClient();
chipbox.Host = ftpHost;
chipbox.Credentials = new NetworkCredential(username, password);
Stream chipboxDosya = chipbox.OpenWrite(fileToWrite);
FileStream dosya = new FileStream(filepathToUpload, FileMode.Open);
try
{
int bufferSize = 8192;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = dosya.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
chipboxDosya.Write(buffer, 0, readCount);
readCount = dosya.Read(buffer, 0, bufferSize);
}
}
finally
{
dosya.Close();
chipboxDosya.Close();
}
}
开发者ID:hktaskin,项目名称:ChipboxHD,代码行数:29,代码来源:FTPTools.cs
示例7: Connect
public static void Connect() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.Connect();
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:7,代码来源:Connect.cs
示例8: GetWorkingDirectory
public static void GetWorkingDirectory() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
Console.WriteLine("The working directory is: {0}",
conn.GetWorkingDirectory());
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:8,代码来源:GetWorkingDirectory.cs
示例9: GetFileSize
public static void GetFileSize() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
Console.WriteLine("The file size is: {0}",
conn.GetFileSize("/full/or/relative/path/to/file"));
}
}
开发者ID:Kylia669,项目名称:DiplomWork,代码行数:8,代码来源:GetFileSize.cs
示例10: DataRefresh
void DataRefresh()
{
try
{
if (TxtData.DataBase.SoapStaus)
{
FtpClient ftp = new FtpClient(TxtData.XMLConfigure.IpAddress);
ftp.DownLoadLog();
if ( !PublicFunc.ReadCs8CLog(out date,out Txt))
{
return;
}
if (date!=null &&Txt!=null)
{
DataView dv = new DataView();
dv.Table = new System.Data.DataTable("Sequen");
dv.Table.Columns.Add();
dv.Table.Columns.Add();
dv.Table.Rows.Clear();
TxtData.CS8CConfigure.ViewPackaging = CB_ViewPackaging.Checked;
for (int i = Txt.Length - 1; i >= 0; i--)
{
if (Txt[i] != null && Txt[i].IndexOf("COM-PC:") < 0)
{
if (TxtData.CS8CConfigure.ViewPackaging)
{
if (Txt[i].IndexOf("USR:")>=0)
{
dv.Table.Rows.Add((object[])new string[] { date[i], Txt[i] });
}
}
else
{
dv.Table.Rows.Add((object[])new string[] { date[i], Txt[i] });
}
}
}
GC_Alarm.DataSource = dv;
gv.Columns[0].Caption = "日期";
gv.Columns[1].Caption = "报警信息";
}
}
}
catch
{
}
}
开发者ID:shumaojie,项目名称:Packaging,代码行数:58,代码来源:Frm_Cs8cAlarm.cs
示例11: ValidateCertificate
public static void ValidateCertificate() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.EncryptionMode = FtpEncryptionMode.Explicit;
conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
conn.Connect();
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:9,代码来源:ValidateCertificate.cs
示例12: SetHashAlgorithm
public static void SetHashAlgorithm() {
using (FtpClient cl = new FtpClient()) {
cl.Credentials = new NetworkCredential("user", "pass");
cl.Host = "some.ftpserver.on.the.internet.com";
if (cl.HashAlgorithms.HasFlag(FtpHashAlgorithm.MD5))
cl.SetHashAlgorithm(FtpHashAlgorithm.MD5);
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:9,代码来源:SetHashAlgorithm.cs
示例13: TestIssue3
public void TestIssue3()
{
var ftpClient = new FtpClient("anonymous",
string.Empty,
"ftp://ftp.mozilla.org");
var ftpListItems = ftpClient.GetListing("/");
Assert.IsNotNull(ftpListItems);
Assert.IsTrue(ftpListItems.Any());
}
开发者ID:dittodhole,项目名称:dotnet-silverlight-ftp,代码行数:9,代码来源:FtpClientTest.cs
示例14: GetHashAlgorithm
public static void GetHashAlgorithm() {
using (FtpClient cl = new FtpClient()) {
cl.Credentials = new NetworkCredential("user", "pass");
cl.Host = "some.ftpserver.on.the.internet.com";
Console.WriteLine("The server is using the following algorithm for computing hashes: {0}",
cl.GetHashAlgorithm());
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:9,代码来源:GetHashAlgorithm.cs
示例15: WindowsServerTest
public void WindowsServerTest()
{
var ftpTestHost = GetTestHost("ftp", "win");
using (var ftpClient = new FtpClient(ftpTestHost.Uri, ftpTestHost.Credential))
{
var i = ftpClient.ServerType;
var s = ftpClient.StatEntries("/").ToArray();
}
}
开发者ID:modulexcite,项目名称:FTP,代码行数:9,代码来源:FtpClientTest.Windows.cs
示例16: DownloadFile
/// <summary>
/// Get remote file. Only FTP supported at present
/// </summary>
/// <param name="file"></param>
/// <param name="destination"></param>
/// <returns></returns>
public static bool DownloadFile(Uri file, string destination)
{
try
{
string[] userInfo = file.UserInfo.Split(new[] { ':' });
if (userInfo.Length != 2)
{
Logger.Warn("No login information in URL!");
return false;
}
using (var cl = new FtpClient(userInfo[0], userInfo[1], file.Host))
{
string remoteFile = file.PathAndQuery;
// Check for existence
#warning DOESN'T SEEM TO WORK ON ALL SERVERS
// if (!cl.FileExists(remoteFile))
// return false;
long size = cl.GetFileSize(remoteFile);
using (FtpDataStream chan = cl.OpenRead(remoteFile))
{
using (var stream = new FileStream(destination, FileMode.Create))
{
using (var writer = new BinaryWriter(stream))
{
var buf = new byte[cl.ReceiveBufferSize];
int read;
long total = 0;
while ((read = chan.Read(buf, 0, buf.Length)) > 0)
{
total += read;
writer.Write(buf, 0, read);
Logger.DebugFormat("\rDownloaded: {0}/{1} {2:p2}",
total, size, (total / (double)size));
}
}
}
// when Dispose() is called on the chan object, the data channel
// stream will automatically be closed
}
// when Dispose() is called on the cl object, a logout will
// automatically be performed and the socket will be closed.
}
}
catch (Exception e)
{
Logger.Warn("Exception downloading file:" + e.Message);
return false;
}
return true;
}
开发者ID:DynamicDevices,项目名称:dta,代码行数:63,代码来源:RemoteFileManager.cs
示例17: FileZillaUnixServerTest
public void FileZillaUnixServerTest()
{
var ftpTestHost = GetTestHost("ftp", "fzx");
using (var ftpClient = new FtpClient(ftpTestHost.Uri, ftpTestHost.Credential))
{
var i = ftpClient.ServerType;
var s = ftpClient.StatEntries("/").ToArray();
}
}
开发者ID:modulexcite,项目名称:FTP,代码行数:9,代码来源:FtpClientTest.FileZilla.cs
示例18: Rename
public static void Rename() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
// renaming a directory is dependant on the server! if you attempt it
// and it fails it's not because System.Net.FtpClient has a bug!
conn.Rename("/full/or/relative/path/to/src", "/full/or/relative/path/to/dest");
}
}
开发者ID:Kylia669,项目名称:DiplomWork,代码行数:9,代码来源:Rename.cs
示例19: DereferenceLinkExample
/// <summary>
/// Example illustrating how to dereference a symbolic link
/// in a file listing. You can also pass the FtpListOption.DerefLinks
/// flag to GetListing() to have automatically done in which
/// case the FtpListItem.LinkObject property will contain the
/// FtpListItem representing the object the link points at. The
/// LinkObject property will be null if there was a problem resolving
/// the target.
/// </summary>
public static void DereferenceLinkExample() {
using (FtpClient client = new FtpClient()) {
client.Credentials = new NetworkCredential("user", "pass");
client.Host = "somehost";
// This propety controls the depth of recursion that
// can be done before giving up on resolving the link.
// You can set the value to -1 for infinite depth
// however you are strongly discourage from doing so.
// The default value is 20, the following line is
// only to illustrate the existance of the property.
// It's also possible to override this value as one
// of the overloaded arguments to the DereferenceLink() method.
client.MaximumDereferenceCount = 20;
// Notice the FtpListOption.ForceList flag being passed. This is because
// symbolic links are only supported in UNIX style listings. My personal
// experience has been that in practice MLSD listings don't specify an object
// as a link, but rather list the link as a regular file or directory
// accordingly. This may not always be the case however that's what I've
// observed over the life of this project so if you run across the contrary
// please report it. The specification for MLSD does include links so it's
// possible some FTP server implementations do include links in the MLSD listing.
foreach (FtpListItem item in client.GetListing(null, FtpListOption.ForceList | FtpListOption.Modify)) {
Console.WriteLine(item);
// If you call DerefenceLink() on a FtpListItem.Type other
// than Link a FtpException will be thrown. If you call the
// method and the LinkTarget is null a FtpException will also
// be thrown.
if (item.Type == FtpFileSystemObjectType.Link && item.LinkTarget != null) {
item.LinkObject = client.DereferenceLink(item);
// The return value of DerefenceLink() will be null
// if there was a problem.
if (item.LinkObject != null) {
Console.WriteLine(item.LinkObject);
}
}
}
// This example is similar except it uses the FtpListOption.DerefLinks
// flag to have symbolic links automatically resolved. You must manually
// specify this flag because of the added overhead with regards to resolving
// the target of a link.
foreach (FtpListItem item in client.GetListing(null,
FtpListOption.ForceList | FtpListOption.Modify | FtpListOption.DerefLinks)) {
Console.WriteLine(item);
if (item.Type == FtpFileSystemObjectType.Link && item.LinkObject != null) {
Console.WriteLine(item.LinkObject);
}
}
}
}
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:65,代码来源:DereferenceLink.cs
示例20: VerifyListing
public void VerifyListing(string host, string username, string password)
{
var ftpClient = new FtpClient();
ftpClient.Host = host;
ftpClient.Credentials = new NetworkCredential(username, password);
ftpClient.Connect();
var listing = ftpClient.GetListing();
Assert.IsNotNull(listing);
}
开发者ID:talanc,项目名称:FtpServerTest,代码行数:10,代码来源:FtpTests.cs
注:本文中的FtpClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论