本文整理汇总了C#中FtpClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.Connect方法的具体用法?C# FtpClient.Connect怎么用?C# FtpClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FtpClient
的用法示例。
在下文中一共展示了FtpClient.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public static void Connect() {
using (FtpClient conn = new FtpClient()) {
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.Connect();
}
}
示例2: 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();
}
}
示例3: 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);
}
示例4: Connect
public void Connect()
{
if (client != null && client.IsConnected)
return;
client = new FtpClient();
client.Host = server;
client.Credentials = new NetworkCredential(login, password);
client.DataConnectionType = FtpDataConnectionType.PASV;
client.Connect();
}
示例5: AppBuilder
public AppBuilder(string user, string pass, string domain, string pathToGame, string pathToSite)
{
this.pathToGame = pathToGame;
this.pathToSite = pathToSite;
this.streams = new List<Stream>();
this.client = new FtpClient();
client.Credentials = new System.Net.NetworkCredential(user, pass, domain);
client.Host = domain;
client.Connect();
}
示例6: ftpConnect
private static void ftpConnect()
{
client = new FtpClient(); // (sftpHost, sftpPort, sftpUsername, sftpPassword);
client.Host = ftpHost;
client.Credentials = new System.Net.NetworkCredential(ftpUsername, ftpPassword);
try
{
client.Connect();
}
catch (Exception e)
{
Console.WriteLine(String.Format("Connection Failed {0}", e));
appendToBody(String.Format("Connection Failed {0}", e));
}
}
示例7: BeginDisconnect
public static void BeginDisconnect() {
// The using statement here is OK _only_ because m_reset.WaitOne()
// causes the code to block until the async process finishes, otherwise
// the connection object would be disposed early. In practice, you
// typically would not wrap the following code with a using statement.
using (FtpClient conn = new FtpClient()) {
m_reset.Reset();
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.Connect();
conn.BeginDisconnect(new AsyncCallback(BeginDisconnectCallback), conn);
m_reset.WaitOne();
}
}
示例8: DownloadBackup
private static void DownloadBackup(string host, string user, string pwd, string ftpDownloadDir)
{
using (var ftp = new FtpClient())
{
ftp.Host = host;
ftp.Credentials = new NetworkCredential { UserName = user, Password = pwd };
ftp.Connect();
foreach (var file in ftp.GetNameListing("/site/wwwroot/App_Data/Backup"))
{
using (var readStream = ftp.OpenRead(file, FtpDataType.Binary))
using (var writeStream = File.Create(Path.Combine(ftpDownloadDir, Path.GetFileName(file))))
{
readStream.CopyTo(writeStream);
}
}
}
}
示例9: DeleteFile
public void DeleteFile(string fileName)
{
using (var ftpClient = new FtpClient())
{
ftpClient.Host = _host;
ftpClient.DataConnectionType = FtpDataConnectionType.AutoActive;
ftpClient.Credentials = new NetworkCredential(_username, _password);
ftpClient.Connect();
// ftpClient.CreateDirectory("/test");
ftpClient.SetWorkingDirectory(_folder);
ftpClient.DeleteFile(_folder + ((_folder == "/") ? "" : "/") + fileName);
ftpClient.Disconnect();
}
}
示例10: GetNameListing
public static void GetNameListing() {
using (FtpClient cl = new FtpClient()) {
cl.Credentials = new NetworkCredential("ftp", "ftp");
cl.Host = "ftp.example.com";
cl.Connect();
foreach (string s in cl.GetNameListing()) {
// load some information about the object
// returned from the listing...
bool isDirectory = cl.DirectoryExists(s);
DateTime modify = cl.GetModifiedTime(s);
long size = isDirectory ? 0 : cl.GetFileSize(s);
}
}
}
示例11: GetOpenFTP
private FtpClient GetOpenFTP()
{
FtpClient cl = null;
try
{
cl = new FtpClient
{
Credentials = new NetworkCredential(_ftpUsername, _ftpPassword),
Host = _ftpHost
};
cl.Connect();
}
catch (Exception)
{
return null;
}
return cl;
}
示例12: FTP
public FTP(Uri target, string password, FtpEncryptionMode mode)
{
_ftp = new FtpClient
{
EncryptionMode = mode,
Host = target.Host,
Port = target.Port,
Credentials = new NetworkCredential(
target.UserInfo,
password
)
};
log.InfoFormat("FTP - Connecting to {0}", target);
_ftp.Connect();
log.InfoFormat("FTP - Changing dir to {0}", target.LocalPath);
_ftp.SetWorkingDirectory(target.LocalPath);
}
示例13: BeginDereferenceLinkExample
public static void BeginDereferenceLinkExample(FtpListItem item) {
// The using statement here is OK _only_ because m_reset.WaitOne()
// causes the code to block until the async process finishes, otherwise
// the connection object would be disposed early. In practice, you
// typically would not wrap the following code with a using statement.
using (FtpClient conn = new FtpClient()) {
m_reset.Reset();
conn.Host = "localhost";
conn.Credentials = new NetworkCredential("ftptest", "ftptest");
conn.Connect();
if (item.Type == FtpFileSystemObjectType.Link && item.LinkTarget != null) {
conn.BeginDereferenceLink(item, new AsyncCallback(DereferenceLinkCallback), conn);
m_reset.WaitOne();
}
conn.Disconnect();
}
}
示例14: TestWorkFlow
public void TestWorkFlow()
{
var config = SetupBootstrap("Basic.config");
using(var client = new FtpClient())
{
client.Host = "localhost";
client.InternetProtocolVersions = FtpIpVersion.IPv4;
client.Credentials = new NetworkCredential("kerry", "123456");
client.DataConnectionType = FtpDataConnectionType.PASV;
client.Connect();
Assert.AreEqual(true, client.IsConnected);
var workDir = client.GetWorkingDirectory();
Assert.AreEqual("/", workDir);
Console.WriteLine("EncryptionMode: {0}", client.EncryptionMode);
foreach (var item in client.GetListing(workDir, FtpListOption.Size))
{
Console.WriteLine(item.Name);
}
}
}
示例15: UploadFile
public string UploadFile(HttpPostedFileBase file)
{
string destinationFile = _folder + ((_folder == "/") ? "" : "/") + Path.GetFileName(file.FileName);
using (var ftpClient = new FtpClient())
{
ftpClient.Host = _host;
ftpClient.Port = 21;
ftpClient.DataConnectionType = FtpDataConnectionType.EPSV;
ftpClient.Credentials = new NetworkCredential(_username, _password);
ftpClient.Connect();
// ftpClient.CreateDirectory("/test");
ftpClient.SetWorkingDirectory(_folder);
byte[] buf = new byte[8192];
int read = 0;
using (var remoteStream = ftpClient.OpenWrite(destinationFile))
{
using (var localStream = new MemoryStream())
{
// Copy the file data from the posted file into a MemoryStream
file.InputStream.CopyTo(localStream);
// Reset position of stream after copy, otherwise we get zero-length files...
localStream.Position = 0;
while ((read = localStream.Read(buf, 0, buf.Length)) > 0)
{
remoteStream.Write(buf, 0, read);
}
}
}
ftpClient.Disconnect();
return Path.GetFileName(destinationFile);
}
}