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


C# FtpClient.Open方法代码示例

本文整理汇总了C#中FtpClient.Open方法的典型用法代码示例。如果您正苦于以下问题:C# FtpClient.Open方法的具体用法?C# FtpClient.Open怎么用?C# FtpClient.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FtpClient的用法示例。


在下文中一共展示了FtpClient.Open方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UploadFile

        public void UploadFile(string filePath)
        {
            if (!_hasAlreadyFixedStrings)
                FixProperties();

            var ftp = new FtpClient(Host, Port, Protocol)
            {
                DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                FileTransferType = TransferType.Binary,
                Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
            };

            try
            {
                ftp.Open(Username, Password.ConvertToUnsecureString());
                ftp.ChangeDirectoryMultiPath(Directory);
                ftp.PutFile(filePath, FileAction.Create);
            }
            finally
            {
                ftp.Close();
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:23,代码来源:TransferService.cs

示例2: UploadPackage

        public void UploadPackage(string packagePath, string packageVersion)
        {
            if (!_hasAlreadyFixedStrings)
                FixProperties();

            _packageFtpClient = new FtpClient();
            _packageFtpClient = new FtpClient(Host, Port, Protocol)
            {
                DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                FileTransferType = TransferType.Binary,
                Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
            };

            try
            {
                _packageFtpClient.TransferProgress += TransferProgressChangedEventHandler;
                _packageFtpClient.PutFileAsyncCompleted += UploadPackageFinished;
                _packageFtpClient.Open(Username, Password.ConvertToUnsecureString());
                _packageFtpClient.ChangeDirectoryMultiPath(Directory);
                _packageFtpClient.MakeDirectory(packageVersion);
                _packageFtpClient.ChangeDirectory(packageVersion);
                _packageFtpClient.PutFileAsync(packagePath, FileAction.Create);
                _uploadPackageResetEvent.WaitOne();
            }
            finally
            {
                _packageFtpClient.Close();
                _uploadPackageResetEvent.Reset();
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:30,代码来源:TransferService.cs

示例3: TestConnection

        public void TestConnection()
        {
            if (!_hasAlreadyFixedStrings)
                FixProperties();

            var ftp = new FtpClient(Host, Port, Protocol)
            {
                DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                FileTransferType = TransferType.Binary,
                Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
            };

            try
            {
                ftp.Open(Username, Password.ConvertToUnsecureString());
            }
            finally
            {
                ftp.Close();
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:21,代码来源:TransferService.cs

示例4: ListDirectoriesAndFiles

        public IEnumerable<FtpItem> ListDirectoriesAndFiles(string path, bool recursive)
        {
            var ftp = new FtpClient(Host, Port, Protocol)
            {
                DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                FileTransferType = TransferType.Binary,
                Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
            };

            try
            {
                ftp.Open(Username, Password.ConvertToUnsecureString());
                FtpItemCollection items = recursive ? ftp.GetDirListDeep(path) : ftp.GetDirList(path);
                return items;
            }
            finally
            {
                ftp.Close();
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:20,代码来源:TransferService.cs

示例5: IsExisting

        public bool IsExisting(string destinationName)
        {
            if (!_hasAlreadyFixedStrings)
                FixProperties();

            var ftp = new FtpClient(Host, Port, Protocol)
            {
                DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                FileTransferType = TransferType.Binary,
                Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
            };

            try
            {
                ftp.Open(Username, Password.ConvertToUnsecureString());
                ftp.ChangeDirectoryMultiPath(Directory);
                string nameList = null;
                try
                {
                    nameList = ftp.GetNameList(destinationName);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("No such file or directory") || ex.Message.Contains("Directory not found"))
                        return false;
                }
                return !string.IsNullOrEmpty(nameList);
            }
            finally
            {
                ftp.Close();
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:33,代码来源:TransferService.cs

示例6: InternalMoveContent

        public void InternalMoveContent(string directory, string aimPath)
        {
            foreach (FtpItem item in ListDirectoriesAndFiles(directory, false)
                .Where(
                    item => item.FullPath != aimPath && item.FullPath != aimPath.Substring(aimPath.Length - 1)))
            {
                FtpClient ftp = null;
                try
                {
                    ftp = new FtpClient(Host, Port, Protocol)
                    {
                        DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                        FileTransferType = TransferType.Binary,
                        Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
                    };
                    ftp.Open(Username, Password.ConvertToUnsecureString());

                    Guid guid; // Just for the out-reference of TryParse
                    if (item.ItemType == FtpItemType.Directory && UpdateVersion.IsValid(item.Name))
                    {
                        ftp.ChangeDirectoryMultiPath(aimPath);
                        if (!IsExisting(aimPath, item.Name))
                            ftp.MakeDirectory(item.Name);
                        ftp.ChangeDirectoryMultiPath(item.Name);

                        InternalMoveContent(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));
                        DeleteDirectory(item.FullPath);
                    }
                    else if (item.ItemType == FtpItemType.File &&
                             (item.Name == "updates.json" || Guid.TryParse(item.Name.Split('.')[0], out guid)))
                        // Second condition determines whether the item is a package-file or not
                    {
                        if (!IsExisting(aimPath, item.Name))
                        {
                            // "MoveFile"-method damages the files, so we do it manually with a work-around
                            //ftp.MoveFile(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));

                            string localFilePath = Path.Combine(Path.GetTempPath(), item.Name);
                            ftp.GetFile(item.FullPath, localFilePath, FileAction.Create);
                            ftp.PutFile(localFilePath, String.Format("{0}/{1}", aimPath, item.Name),
                                FileAction.Create);
                            File.Delete(localFilePath);
                        }
                        DeleteFile(item.ParentPath, item.Name);
                    }
                }
                finally
                {
                    if (ftp != null)
                        ftp.Close();
                }
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:53,代码来源:TransferService.cs

示例7: DeleteDirectory

        public void DeleteDirectory(string directoryPath)
        {
            if (!_hasAlreadyFixedStrings)
                FixProperties();

            var ftp = new FtpClient(Host, Port, Protocol);
            try
            {
                IEnumerable<FtpItem> items = ListDirectoriesAndFiles(directoryPath, true);
                ftp.DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active;
                ftp.FileTransferType = TransferType.Binary;
                ftp.Proxy = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null;
                ftp.Open(Username, Password.ConvertToUnsecureString());
                foreach (FtpItem item in items)
                {
                    switch (item.ItemType)
                    {
                        case FtpItemType.Directory:
                            DeleteDirectory(String.Format("/{0}/{1}/", directoryPath, item.Name));
                            break;
                        case FtpItemType.File:
                            DeleteFile(directoryPath, item.Name);
                            break;
                    }
                }
                ftp.DeleteDirectory(directoryPath);
            }
            finally
            {
                ftp.Close();
            }
        }
开发者ID:chantsunman,项目名称:nUpdate,代码行数:32,代码来源:TransferService.cs


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