当前位置: 首页>>代码示例>>C#>>正文


C# FtpClient.Connect方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:7,代码来源:Connect.cs

示例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();
     }
 }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:9,代码来源:ValidateCertificate.cs

示例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);
        }
开发者ID:talanc,项目名称:FtpServerTest,代码行数:10,代码来源:FtpTests.cs

示例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();
        }
开发者ID:abhinavc,项目名称:winbot,代码行数:11,代码来源:FaTaPhat.cs

示例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();
        }
开发者ID:nikoladimitroff,项目名称:thralldom,代码行数:12,代码来源:AppBuilder.cs

示例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));
     }
 }
开发者ID:robertmcconnell2007,项目名称:CCCommunications,代码行数:15,代码来源:Program.cs

示例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();
            }
        }
开发者ID:Kylia669,项目名称:DiplomWork,代码行数:16,代码来源:BeginDisconnect.cs

示例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);
             }
         }
     }
 }
开发者ID:kruglik-alexey,项目名称:jeegoordah,代码行数:17,代码来源:Program.cs

示例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();
            }
        }
开发者ID:markashleybell,项目名称:microwiki,代码行数:17,代码来源:RemoteFileManager.cs

示例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);

                    
                }
            }
        }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:17,代码来源:GetNameListing.cs

示例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;
 }
开发者ID:andbene72,项目名称:SkypeStatusChanger,代码行数:18,代码来源:FtpOnline.cs

示例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);
        }
开发者ID:1aurent,项目名称:CloudBackup,代码行数:19,代码来源:FTP.cs

示例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();
            }
        }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:20,代码来源:BeginDereferenceLink.cs

示例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);
                }
            }
        }
开发者ID:jmptrader,项目名称:SuperSocket.FtpServer,代码行数:21,代码来源:BasicTest.cs

示例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);
            }
        }
开发者ID:markashleybell,项目名称:microwiki,代码行数:39,代码来源:RemoteFileManager.cs


注:本文中的FtpClient.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。