本文整理汇总了C#中FtpClient类的典型用法代码示例。如果您正苦于以下问题:C# FtpClient类的具体用法?C# FtpClient怎么用?C# FtpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FtpClient类属于命名空间,在下文中一共展示了FtpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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");
}
}
示例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);
}
}
示例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");
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例7: Connect
public static void Connect() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.Connect();
}
}
示例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());
}
}
示例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"));
}
}
示例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
{
}
}
示例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();
}
}
示例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);
}
}
示例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());
}
示例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());
}
}
示例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();
}
}