示例#1
0
 public bool DownloadFile(FTPFile fily)
 {
     try
     {
         string destPath = fily.LocalFullPath;
         if (!Directory.Exists(fily.getLocalFolder()))
         {
             //Create Folder
             Directory.CreateDirectory(fily.getLocalFolder());
         }
         using (var ftpStream = getFTPClient().OpenRead(fily.FullPath))
             if ((int)ftpStream.Length == 0)
             {
                 if (!File.Exists(destPath))
                 {
                     File.Create(destPath).Dispose();
                 }
                 else
                 {
                     File.Create(destPath).Dispose();
                 }
             }
             else
             {
                 //bool doOverwrite = true;
                 //if (File.Exists(destPath))
                 //{
                 //    byte[] file1 = File.ReadAllBytes(destPath);
                 //    if (file1.Length == file.ftpListItem.Size)
                 //    {
                 //        doOverwrite = false;
                 //    }
                 //}
                 //if (doOverwrite)
                 //{
                 using (var fileStream = File.Create(destPath, (int)ftpStream.Length))
                 {
                     var buffer = new byte[8 * 1024];
                     int count;
                     while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
                     {
                         fileStream.Write(buffer, 0, count);
                     }
                 }
                 //}
             }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#2
0
 public static Boolean hasDiff(string path, FTPFile toCheck)
 {
     toCheck.LocalFullPath = Path.Combine(path, toCheck.getPathForLocalWithContent());
     if (File.Exists(toCheck.LocalFullPath))
     {
         long length = new FileInfo(toCheck.LocalFullPath).Length;
         toCheck.ExistsLocal = true;
         if (length != toCheck.SizeByte)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }