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


C# FtpClient.FileExists方法代码示例

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


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

示例1: FileExists

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

                // The last parameter forces System.Net.FtpClient to use LIST -a 
                // for getting a list of objects in the parent directory.
                if (conn.FileExists("/full/or/relative/path", 
                    FtpListOption.ForceList | FtpListOption.AllFiles)) {
                    // dome something
                }
            }
        }
开发者ID:Kylia669,项目名称:DiplomWork,代码行数:13,代码来源:FileExists.cs

示例2: UploadBackupFile

        private void UploadBackupFile(FtpClient ftpClient, string ftpBackupPath, string backupFilePath)
        {
            Stream ftpBackupFile;
              long totalBytesWritten = 0;

              var backupFilename = Path.GetFileName(backupFilePath);

              var ftpBackupFilePath = ftpBackupPath + "/" + backupFilename;

              if (ftpClient.FileExists(ftpBackupFilePath))
              {
            var ftpBackupFileSize = ftpClient.GetFileSize(ftpBackupFilePath);

            totalBytesWritten = ftpBackupFileSize;

            ftpBackupFile = ftpClient.OpenAppend(ftpBackupPath + "/" + backupFilename, FtpDataType.Binary);
              }
              else
              {
            ftpBackupFile = ftpClient.OpenWrite(ftpBackupPath + "/" + backupFilename, FtpDataType.Binary);
              }

              try
              {
            using (var backupFile = File.OpenRead(backupFilePath))
            {
              int bytesRead;
              var totalBytes = backupFile.Length;
              var bytesWrittenLogPoint = 0.1;

              var buffer = new byte[4096];

              _log.Info(string.Format("Uploading {0} ({1:N0} bytes)...", backupFilename, totalBytes));

              if (totalBytesWritten > 0)
            backupFile.Seek(totalBytesWritten, SeekOrigin.Begin);

              while ((bytesRead = backupFile.Read(buffer, 0, buffer.Length)) > 0)
              {
            ftpBackupFile.Write(buffer, 0, bytesRead);

            totalBytesWritten += bytesRead;

            var writtenBytesPercentage = ((float)totalBytesWritten / totalBytes);

            if (writtenBytesPercentage >= bytesWrittenLogPoint)
            {
              _log.Info(
                string.Format(
                  "Backup file upload progress: {0:P} ({1:N0} bytes) of {2}.",
                  writtenBytesPercentage,
                  totalBytesWritten,
                  backupFilename));

              bytesWrittenLogPoint += 0.1;
            }
              }
            }
              }
              finally
              {
            ftpBackupFile.Dispose();
              }
        }
开发者ID:eranbetzalel,项目名称:SimpleBackup,代码行数:64,代码来源:BackupStorageService.cs

示例3: UnsetOnlineStatus

        private bool UnsetOnlineStatus(FtpClient cl)
        {
            UserStatus onlineStatus = UserStatus.Unknown;
            try
            {
                string[] sa;
                sa = cl.GetNameListing(_ftpSkypeDir + _account);

                foreach (var iterateStatus in Enum.GetValues(typeof (UserStatus)))
                {
                    bool found = false;

                    foreach (var s in sa)
                    {
                        int indir;
                        if (int.TryParse(s.Substring(0,s.IndexOf(".", StringComparison.Ordinal)), out indir))
                        {
                            if (indir == (int) iterateStatus)
                            {
                                found = true;
                                break;
                            }
                        }
                    }
                    if (!found)
                    {
                        onlineStatus = (UserStatus) iterateStatus;
                        break;
                    }
                }

                if (cl.FileExists(_ftpSkypeDir + _account + "/current.png"))
                {
                    cl.Rename(_ftpSkypeDir + _account + "/current.png",
                        _ftpSkypeDir + _account + "/" + (int)onlineStatus + ".png");
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
开发者ID:andbene72,项目名称:SkypeStatusChanger,代码行数:43,代码来源:FtpOnline.cs


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