示例#1
0
 /// <summary>
 /// Recursive scan of files an folders
 /// If something not exists or a Filesize not the same it will retunr true for the hole subfolder
 /// </summary>
 /// <param name="path"></param>
 /// <param name="toCheck"></param>
 /// <returns></returns>
 public static Boolean hasDiff(string path, FTPDirectoryDirect toCheck)
 {
     foreach (FTPFileDirect ftpFile in toCheck.lstFiles)
     {
         if (File.Exists(Path.Combine(path, ftpFile.ftpListItem.Name)))
         {
             byte[] file1 = File.ReadAllBytes(Path.Combine(path, ftpFile.ftpListItem.Name));
             if (file1.Length != ftpFile.ftpListItem.Size)
             {
                 return(true);
             }
         }
         else
         {
             return(true);
         }
     }
     foreach (FTPDirectoryDirect ftpDir in toCheck.subDirectories)
     {
         if (hasDiff(Path.Combine(path, ftpDir._name), ftpDir))
         {
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        public void FillListItems(FTPDirectoryDirect dirToAdd, string subfolder = "", int deep = 0, int maxDeep = 100, FrmMain frmMain = null, int progressVal = 0, int progressMax = 1000)
        {
            List <FtpListItem> lstItems = getFTPClient().GetListing(subfolder).ToList();

            foreach (FtpListItem ftpli in lstItems)
            {
                progressVal += 1;
                if (frmMain != null)
                {
                    frmMain.SetProgress(progressVal, progressMax, "Found Folder " + ftpli.FullName + " (" + progressVal + ")");
                }
                if (ftpli.Type == FtpFileSystemObjectType.Directory)
                {
                    FTPDirectoryDirect newDir = new FTPDirectoryDirect(ftpli.Name, ftpli.FullName, dirToAdd, dirToAdd._deep + 1);
                    if (newDir._deep <= maxDeep)
                    {
                        FillListItems(newDir, newDir._fullpath, newDir._deep, maxDeep);
                    }
                    dirToAdd.subDirectories.Add(newDir);
                }
                else
                {
                    dirToAdd.lstFiles.Add(new FTPFileDirect(ftpli, dirToAdd));
                }
            }
        }
示例#3
0
        public FTPDirectoryDirect GetFTPHoleTree(string path, string username = "", string password = "", int maxDeep = 100, FrmMain frmMain = null)
        {
            FTPDirectoryDirect root = new FTPDirectoryDirect();

            root._name     = path;
            root._fullpath = path;
            root._deep     = 0;
            if (!path.Equals(rootPath) || getFTPClient().IsConnected == false)
            {
                rootPath  = path;
                _username = username;
                _password = password;
                if (_username.Equals(""))
                {
                    _username = "******";
                }
            }
            if (getFTPClient().IsConnected == false)
            {
                return(null);
            }
            //Root Elemente befüllen
            FillListItems(root, "", root._deep + 1, maxDeep, frmMain, 1, 10000);
            return(root);
        }
示例#4
0
 public FTPDirectoryDirect(string name, string fullpath, FTPDirectoryDirect parentDir, int deep)
 {
     this._name     = name;
     this._fullpath = fullpath;
     _parentDir     = parentDir;
     _deep          = deep;
 }
示例#5
0
        private void CreateAllFilesAndFolders(FTPDirectoryDirect ftpDir, FrmMain frmMain, int curVal, int maxVal)
        {
            foreach (FTPDirectoryDirect dir in ftpDir.subDirectories)
            {
                dir._localPath = Path.Combine(ftpDir._localPath, dir._name);

                curVal++;
                frmMain.SetProgress(curVal, maxVal, "Ordner " + dir._localPath + " wird überprüft!");
                if (!Directory.Exists(dir._localPath))
                {
                    Directory.CreateDirectory(dir._localPath);
                }
                CreateAllFilesAndFolders(dir, frmMain, curVal, maxVal);
            }
            foreach (FTPFileDirect file in ftpDir.lstFiles)
            {
                try {
                    string destPath = Path.Combine(ftpDir._localPath, file.ftpListItem.Name);
                    using (var ftpStream = getFTPClient().OpenRead(file.ftpListItem.FullName))
                        if ((int)ftpStream.Length == 0)
                        {
                            if (!File.Exists(destPath))
                            {
                                System.IO.File.WriteAllLines(destPath, new string[0]);
                            }
                        }
                        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);
                                    }
                                }
                                frmMain.SetProgress(curVal, maxVal, "File " + destPath + " wird angelegt!");
                            }
                        }
                }
                catch
                {
                }
                curVal++;
            }
        }
示例#6
0
        public static IEnumerable <FTPDirectoryDirect> Descendants(this FTPDirectoryDirect root)
        {
            var nodes = new Stack <FTPDirectoryDirect>(new[] { root });

            while (nodes.Any())
            {
                FTPDirectoryDirect node = nodes.Pop();
                yield return(node);

                foreach (var n in node.subDirectories)
                {
                    nodes.Push(n);
                }
            }
        }
示例#7
0
        public void DownloadFolder(FTPDirectoryDirect toSync, FrmMain frmMain, int curFolder, int maxFolder)
        {
            int curVal = curFolder * 3 + 1;
            int maxVal = maxFolder * 3;

            frmMain.SetProgress(curVal, maxVal, "Der Baum des Ordners(" + curFolder + "," + maxFolder + ") wird noch einmal ganz durchsucht!");
            FillListItems(toSync, toSync._fullpath, toSync._deep + 1);
            //Verzeichnis erstellen
            if (!Directory.Exists(toSync._localPath))
            {
                Directory.CreateDirectory(toSync._localPath);
            }
            int anzObjekte = toSync.Descendants().Count();

            anzObjekte += toSync.Descendants().Select(x => x.lstFiles.Count).Sum();

            curVal = curVal + 1;
            frmMain.SetProgress(curVal, maxVal, "Ordner und Files werden angelegt! Anzahl Objekte:" + anzObjekte);
            curVal = anzObjekte * curVal;
            maxVal = anzObjekte * maxVal;
            CreateAllFilesAndFolders(toSync, frmMain, curVal, maxVal);
        }
示例#8
0
 public FTPFileDirect(FtpListItem file, FTPDirectoryDirect dir)
 {
     ftpListItem  = file;
     ftpDirectory = dir;
 }