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


C# FtpClient.DirectoryExists方法代码示例

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


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

示例1: DeleteDirectory

        public static void DeleteDirectory() {
            using (FtpClient conn = new FtpClient()) {
                conn.Host = "localhost";
                conn.Credentials = new NetworkCredential("ftptest", "ftptest");

                if (conn.DirectoryExists("/full/or/relative/path")) {
                    // do something
                }

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

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

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

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

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

示例6: ClearFiles

        private void ClearFiles(FtpClient ftpClient, string remoteDir) {
            if(ftpClient.DirectoryExists(remoteDir) == false)
                return;

            foreach(var file in Client.ListDirectoryDetail(remoteDir).GetFiles()) {
                ftpClient.DeleteFile(file.FullName);
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:8,代码来源:FtpClientFixture.cs


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