Esempio n. 1
0
        /// <summary>
        ///     Returns a non-recursive list of files/folders inside the specified path
        /// </summary>
        /// <param name="cpath">path to folder to list inside</param>
        /// <param name="skipIgnored">if true, ignored items are not returned</param>
        public IEnumerable <ClientItem> List(string cpath, bool skipIgnored = true)
        {
            ListingFailed = false;
            UnsetKeepAlive();

            List <ClientItem> list;

            try
            {
                list = FTP
                    ? Array.ConvertAll(new List <FtpListItem>(_ftpc.GetListing(cpath)).ToArray(), ConvertItem).ToList()
                    : Array.ConvertAll(new List <SftpFile>(_sftpc.ListDirectory(cpath)).ToArray(), ConvertItem).ToList();
            }
            catch (Exception ex)
            {
                Common.LogError(ex);
                ListingFailed = true;
                yield break;
            }

            list.RemoveAll(x => x.Name == "." || x.Name == "..");
            if (skipIgnored)
            {
                list.RemoveAll(x => x.FullPath.Contains("webint"));
            }

            foreach (var f in list.Where(x => x.Type != ClientItemType.Other))
            {
                yield return(f);
            }

            SetKeepAlive();
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a non-recursive list of files/folders inside the specified path
        /// </summary>
        /// <param name="cpath">path to folder to list inside</param>
        /// <param name="skipIgnored">if true, ignored items are not returned</param>
        public IEnumerable <ClientItem> List(string cpath, bool skipIgnored = true)
        {
            ListingFailed = false;

            var list = new List <ClientItem>();
            var cd   = string.Empty;

            // Fix for folders that contain spaces: The client will cd inside any
            // such folder and request a file/folder listing of the current directory
            if (FTP && cpath.PathHasSpace())
            {
                cd = WorkingDirectory;
                if (!cd.Equals(cpath))
                {
                    string path = cpath.StartsWithButNotEqual(cd + "/") ? cpath.Substring(cd.Length + 1) : cpath;
                    Log.Write(l.Client, "changing dir to: {0} from wd: {1}", cpath, cd);
                    cpath = ".";
                    _ftpc.ChangeDirectoryMultiPath(path);
                }
            }
            try
            {
                if (FTP)
                {
                    list = Array.ConvertAll(new List <FtpItem>(_ftpc.GetDirList(cpath)).ToArray(), ConvertItem).ToList();
                }
                else
                {
                    list = Array.ConvertAll(new List <SftpFile>(_sftpc.ListDirectory(cpath)).ToArray(), ConvertItem).ToList();
                }
            }
            catch (Exception ex)
            {
                Common.LogError(ex);
                ListingFailed = true;
                yield break;
            }

            list.RemoveAll(x => x.Name == "." || x.Name == "..");
            if (skipIgnored)
            {
                list.RemoveAll(x => x.FullPath.Contains("webint"));
            }

            // If we changed directory, we should go back...
            if (FTP && cpath == "." && cd != string.Empty)
            {
                while (WorkingDirectory != cd)
                {
                    _ftpc.ChangeDirectoryMultiPath("..");
                }
            }

            foreach (var f in list.Where(x => x.Type == ClientItemType.File || x.Type == ClientItemType.Folder))
            {
                yield return(f);
            }
        }
Esempio n. 3
0
        public List <ClientItem> List(string path)
        {
            List <ClientItem> l = new List <ClientItem>();

            if (path.StartsWith("/"))
            {
                path = path.Substring(1);
            }

            if (FTP)
            {
                foreach (FtpItem f in ftpc.GetDirList(path))
                {
                    ClientItemType t;
                    switch (f.ItemType)
                    {
                    case FtpItemType.File:
                        t = ClientItemType.File;
                        break;

                    case FtpItemType.Directory:
                        t = ClientItemType.Folder;
                        break;

                    default:
                        t = ClientItemType.Other;
                        break;
                    }
                    l.Add(new ClientItem(f.Name, f.FullPath, t));
                }
            }
            else
            {
                foreach (SftpFile s in sftpc.ListDirectory(path))
                {
                    if (s.Name != "." && s.Name != "..")
                    {
                        ClientItemType t;
                        if (s.IsRegularFile)
                        {
                            t = ClientItemType.File;
                        }
                        else if (s.IsDirectory)
                        {
                            t = ClientItemType.Folder;
                        }
                        else
                        {
                            t = ClientItemType.Other;
                        }

                        l.Add(new ClientItem(s.Name, s.FullName, t));
                    }
                }
            }

            return(l);
        }
Esempio n. 4
0
        /// <summary>
        ///     Returns a non-recursive list of files/folders inside the specified path
        /// </summary>
        /// <param name="cpath">path to folder to list inside</param>
        /// <param name="skipIgnored">if true, ignored items are not returned</param>
        public override IEnumerable <ClientItem> List(string cpath, bool skipIgnored = true)
        {
            ListingFailed = false;
            UnsetKeepAlive();

            List <ClientItem> list = new List <ClientItem>();

            lock (ftpcLock)
            {
                bool ok = false;

                while (!ok)
                {
                    try
                    {
                        if (_controller.Client.WorkingDirectory.CompareTo(_controller.Paths.Remote) != 0)
                        {
                            _controller.Client.WorkingDirectory = _controller.Paths.Remote;
                        }

                        Notifications.ChangeTrayText(MessageType.Scanning, null, 0, cpath);
                        var Listed = _sftpc.ListDirectory(cpath);
                        list = Array.ConvertAll(new List <SftpFile>(Listed).ToArray(), ConvertItem).ToList();
                        ok   = true;
                    }
                    catch (TimeoutException ex)
                    {
                        Common.LogError(ex);
                    }
                    catch (Exception ex)
                    {
                        Common.LogError(ex);
                        yield break;
                    }
                }
            }

            list.RemoveAll(x => x.Name == "." || x.Name == "..");

            foreach (var f in list.Where(x => x.Type != ClientItemType.Other))
            {
                yield return(f);
            }

            SetKeepAlive();
        }