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


C# FtpClient.CreateDirectory方法代码示例

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


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

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

示例2: BeginDeleteDirectory

        public static void BeginDeleteDirectory() {
            // 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.CreateDirectory("/some/test/directory");
                conn.BeginDeleteDirectory("/some", true, new AsyncCallback(DeleteDirectoryCallback), conn);

                m_reset.WaitOne();
                conn.Disconnect();
            }
        }
开发者ID:fanpan26,项目名称:Macrosage.Wx,代码行数:17,代码来源:BeginDeleteDirectory.cs

示例3: ProcessStorageReadyBackupEntry

        public bool ProcessStorageReadyBackupEntry(BackupHistoryEntry backupEntryToStorage)
        {
            try
              {
            if (!backupEntryToStorage.StoragePendingFilesPaths.Any())
            {
              _log.Debug("No files to store.");

              return true;
            }

            var relativeFtpBackupDirectory =
              _settingsProvider.GetSetting<string>("RelativeFtpBackupDirectory").TrimEnd('/', '\\');

            using (var ftpClient = new FtpClient())
            {
              ftpClient.DataConnectionType = _dataConnectionType;

              ftpClient.Host = _settingsProvider.GetSetting<string>("FtpHost");
              ftpClient.Port = _settingsProvider.GetSetting<int>("FtpPort");

              ftpClient.Credentials =
            new NetworkCredential(
              _settingsProvider.GetSetting<string>("FtpUsername"),
              _settingsProvider.GetSetting<string>("FtpPassword"));

              _log.Info("Connecting to FTP server (" + ftpClient.Host + ":" + ftpClient.Port + ")...");

              ftpClient.Connect();

              var ftpBackupPath =
            string.Format(
              "{0}/{1} {2} Backup",
              relativeFtpBackupDirectory,
              backupEntryToStorage.CompressStarted.ToString("yyyyMMdd_HHmmss"),
              backupEntryToStorage.BackupType);

              ftpClient.CreateDirectory(ftpBackupPath);

              //  Upload compressed backups to FTP server
              foreach (var storagePendingFilePath in backupEntryToStorage.StoragePendingFilesPaths)
              {
            UploadBackupFile(ftpClient, ftpBackupPath, storagePendingFilePath);
              }

              //  Removed already uploaded backup files
              foreach (var storagePendingFilePath in backupEntryToStorage.StoragePendingFilesPaths)
              {
            File.Delete(storagePendingFilePath);
              }

              _log.Info("Finished uploading files to the FTP server.");
            }

            return true;
              }
              catch (Exception e)
              {
            _log.Error("Failed to upload files to FTP server.", e);

            return false;
              }
        }
开发者ID:eranbetzalel,项目名称:SimpleBackup,代码行数:63,代码来源:BackupStorageService.cs

示例4: uploadFTP

        /// <summary>
        /// Uploads a file to FTP
        /// </summary>
        /// <param name="localFileName">Local file to upload</param>
        /// <param name="uploadPath">URI of the file to upload</param>
        /// <param name="silent"></param>
        /// <param name="ignoreError"></param>
        /// <param name="errorActions"></param>
        public static void uploadFTP(string Host, string localFileName, string serverPath, NetworkCredential Credentials, bool silent = false, bool ignoreError = false, string[] errorActions = null)
        {
            try
            {
                int bufferSize = 8192;
                FtpClient FTP = new FtpClient();
                FTP.ValidateCertificate += FTPClient_ValidateCertificate;
                FTP.Host = Host;
                FTP.Credentials = Credentials;
                FTP.Connect();

                if (!silent) Logging.logMessage("Connected to: " + Host, 1);

                if (!FTP.DirectoryExists(serverPath))
                {
                    Logging.logMessage("Created directory on server: " + serverPath);
                    FTP.CreateDirectory(serverPath);
                }

                FileStream localFile = new FileStream(localFileName, FileMode.OpenOrCreate);
                byte[] Buffer = new byte[bufferSize];
                Stream writeStream = FTP.OpenWrite(serverPath + Path.GetFileName(localFileName), FtpDataType.Binary);
                int bytesSent = localFile.Read(Buffer, 0, bufferSize);

                while (bytesSent != 0)
                {
                    writeStream.Write(Buffer, 0, bytesSent);
                    bytesSent = localFile.Read(Buffer, 0, bufferSize);
                }

                localFile.Close();
                writeStream.Close();
                FTP.Dispose();

                if (!silent) Logging.logMessage("Disconnedted from FTP server", 1);

            }
            catch (Exception e)
            {
                if (!ignoreError) Logging.showError("Failed to upload file via FTP:" + Environment.NewLine + e.ToString(), errorActions);
            }

        }
开发者ID:RX14,项目名称:RX-UTILS.NET,代码行数:51,代码来源:Web.cs

示例5: createFtpDirectory

		private void createFtpDirectory(FtpClient client, string directory) {
			try {
				if (!client.DirectoryExists(directory) && directory.Length > 1)
					client.CreateDirectory(directory);
			}
			catch (FtpException ftpExc) {
				if (ftpExc.Message.Contains("file or directory already exists"))
					writeLogEntry(logLevel.Error, string.Format("client.CreateDirectory fehlgeschlagen: {0}", ftpExc.Message));
				else
					throw;
			}
		}
开发者ID:Taipi88,项目名称:updateSystem.NET,代码行数:12,代码来源:pbsFtp.cs

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

示例7: UploadFiles

        private void UploadFiles(FtpClient ftpClient, string remoteDir) {
            if(!ftpClient.DirectoryExists(remoteDir))
                ftpClient.CreateDirectory(remoteDir);

            var fis = new FileInfo[FileCount];

            for(int i = 0; i < FileCount; i++) {
                string file = LocalFileHeader + i;

                if(!File.Exists(file))
                    fis[i] = CreateTestFile(LocalFileHeader + i, BufferSize * 1024 * (i + 1));
                else
                    fis[i] = new FileInfo(file);
            }

            for(int i = 0; i < FileCount; i++) {
                using(new OperationTimer("Upload File:" + fis[i].FullName))
                    ftpClient.Upload(fis[i], RemoteFileHeader + i).Should().Be.True();

                fis[i].Delete();
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:22,代码来源:FtpClientFixture.cs


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