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


C# FtpClient.ChangeDirectory方法代码示例

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


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

示例1: Write

 public static Stream Write(string path)
 {
     var diskpath = Paths.Map(path);
     if (Paths.IsWritable(path)) return new FileStream(diskpath, FileMode.Create, FileAccess.Write);
     else if (CanUseFtp) {
         var pipe = new PipeStream();
         Tasks.Do(() => {
             using (pipe)
             using (var ftp = new FtpClient()) {
                 string dir, name;
                 ftp.Split(path, out dir, out name);
                 ftp.ChangeDirectory(dir);
                 ftp.PutFile(pipe, name, Ftp.FileAction.Create);
                 ftp.Close();
             }
         });
         return pipe;
     }
     throw new IOException(string.Format("Path {0} is write protected.", path));
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:20,代码来源:Files.cs

示例2: Save

 public static void Save(Stream src, string path)
 {
     if (Paths.IsWritable(path)) {
         SaveRaw(src, Paths.Map(path));
     } else if (CanUseFtp) {
         using (var ftp = new FtpClient()) {
             string dir, name;
             ftp.Split(path, out dir, out name);
             ftp.ChangeDirectory(dir);
             ftp.PutFile(src, name, Ftp.FileAction.Create);
             ftp.Close();
         }
     } else throw new IOException(string.Format("Path {0} is write protected.", path));
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:14,代码来源:Files.cs

示例3: Delete

 public static void Delete(IEnumerable<string> paths)
 {
     paths.Each(path => {
         if (path.Contains("*")) All(path).Each(p => Delete(p));
         path = Paths.Normalize(path);
         var ftppath = path.Substring(1);
         var diskpath = Paths.Map(path);
         if (Directory.Exists(diskpath)) {
             if (Paths.IsWritable(path)) {
                 try {
                     Directory.Delete(diskpath, true);
                 } catch {
                     var info = new DirectoryInfo(diskpath);
                     var children = info.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).ToList();
                     foreach (var file in children.OfType<FileInfo>()) File.Delete(file.FullName);
                     children.Reverse();
                     foreach (var dir in children.OfType<DirectoryInfo>()) Directory.Delete(dir.FullName);
                 }
             } else if (CanUseFtp) {
                 using (var ftp = new FtpClient()) {
                     ftp.DeleteDirectoryRecursive(ftppath);
                     ftp.Close();
                 }
             } else throw new IOException(string.Format("Path {0} is write protected.", path));
         } else if (File.Exists(diskpath)) {
             if (Paths.IsWritable(path)) File.Delete(diskpath);
             else if (CanUseFtp) {
                 using (var ftp = new FtpClient()) {
                     string dir, name;
                     ftp.Split(path, out dir, out name);
                     ftp.ChangeDirectory(dir);
                     ftp.DeleteFile(name);
                     ftp.Close();
                 }
             } else throw new IOException(string.Format("Path {0} is write protected.", path));
         }
     });
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:38,代码来源:Files.cs

示例4: CreateDirectory

 public static void CreateDirectory(IEnumerable<string> paths)
 {
     foreach (var path in paths) {
         var diskpath = Paths.Map(path);
         if (!Directory.Exists(diskpath)) {
             if (Paths.IsWritable(path)) Directory.CreateDirectory(diskpath);
             else if (CanUseFtp) {
                 using (var ftp = new FtpClient()) {
                     string dir, name;
                     ftp.Split(path, out dir, out name);
                     if (!dir.IsNullOrEmpty()) ftp.ChangeDirectory(dir);
                     ftp.MakeDirectory(name);
                     ftp.Close();
                 }
             } else throw new IOException(string.Format("Path {0} is write protected.", path));
         }
     }
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:18,代码来源:Files.cs

示例5: Main

        static void Main(string[] args)
        {
            // Código para testar as funcionalidades do FTP
            Console.WriteLine("Informe os dados da conexão\n");

            Console.Write("Servidor ............: ");
            var remoteHost = Console.ReadLine();
            
            Console.Write("Porta (default 21) ..: ");
            var remotePort = Int32.Parse(Console.ReadLine());
            
            Console.Write("Usuário .............: ");
            var userName = Console.ReadLine();

            Console.Write("Senha ...............: ");
            var password = ConsoleHelper.ReadLine(true);

            Console.WriteLine();

            try
            {
                bool success;
                var ftpClient = new FtpClient(remoteHost, remotePort, userName, password);

                if ((success = ftpClient.Connect()) == true)
                {
                    TraceHelper.WriteLine("*** Conectado!");
                    TraceHelper.WriteLine(string.Format("*** Diretório atual: {0}", ftpClient.GetCurrentDirectory()));
                }

                if (success && ((success = ftpClient.ChangeDirectory("web")) == true))
                {
                    TraceHelper.WriteLine("*** Diretório alterado com sucesso!");
                    TraceHelper.WriteLine(string.Format("*** Diretório atual: {0}", ftpClient.GetCurrentDirectory()));
                }

                if (success)
                {
                    var fileSize = ftpClient.GetFileSize("Sun.zip");

                    TraceHelper.WriteLine(string.Format("*** O arquivo Sun.zip tem {0} bytes", fileSize));
                }

                if (success && ((success = ftpClient.CreateDirectory("FtpClientTest")) == true))
                {
                    TraceHelper.WriteLine("*** Diretório [FtpClientTest] criado com sucesso!");
                }

                if (success && ((success = ftpClient.RemoveDirectory("FtpClientTest")) == true))
                {
                    TraceHelper.WriteLine("*** Diretório [FtpClientTest] removido com sucesso!");
                }

                if (success && ((success = ftpClient.ChangeToParentDirectory()) == true))
                {
                    TraceHelper.WriteLine("*** Voltou para o diretório raiz");
                    TraceHelper.WriteLine(string.Format("*** Diretório atual: {0}", ftpClient.GetCurrentDirectory()));
                }

                if (success && ((success = ftpClient.List()) == true))
                {
                    TraceHelper.WriteLine("*** Listagem efetuada com sucesso");
                }
            }
            catch (Exception exception)
            {
                TraceHelper.WriteLine(string.Format("*** Ocorreu o seguinte erro durante a comunicação com o servidor FTP: {0}", exception.Message));
            }

            Console.ReadKey(true);
        }
开发者ID:luhcmps,项目名称:LSCoder.Net.Ftp,代码行数:71,代码来源:Program.cs

示例6: 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


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