Renci.SshNet.SftpClient.InternalListDirectory C# (CSharp) Method

InternalListDirectory() private method

Internals the list directory.
is null. Client not connected.
private InternalListDirectory ( string path, Action listCallback ) : IEnumerable
path string The path.
listCallback Action The list callback.
return IEnumerable
        private IEnumerable<SftpFile> InternalListDirectory(string path, Action<int> listCallback)
        {
            if (path == null)
                throw new ArgumentNullException("path");

            if (_sftpSession == null)
                throw new SshConnectionException("Client not connected.");

            var fullPath = _sftpSession.GetCanonicalPath(path);

            var handle = _sftpSession.RequestOpenDir(fullPath);

            var basePath = fullPath;

            if (!basePath.EndsWith("/"))
                basePath = string.Format("{0}/", fullPath);

            var result = new List<SftpFile>();

            var files = _sftpSession.RequestReadDir(handle);

            while (files != null)
            {
                result.AddRange(from f in files
                                select new SftpFile(_sftpSession, string.Format(CultureInfo.InvariantCulture, "{0}{1}", basePath, f.Key), f.Value));

                //  Call callback to report number of files read
                if (listCallback != null)
                {
                    //  Execute callback on different thread
                    ThreadAbstraction.ExecuteThread(() => listCallback(result.Count));
                }

                files = _sftpSession.RequestReadDir(handle);
            }

            _sftpSession.RequestClose(handle);

            return result;
        }