Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

t0r3x

Well, seems that I found out why it was slow. I took the example a bit too literally, disposing of the session every time ofcouse was the reason why it was slow. I now only keep one session instance which I only terminate when I am done with everything WinSCP. First time listing the directory is going to be slow because of setting up the connection. I now found out by doing it in the example way I was setting up the connection time and time again for every directory listing. Sorry to have bothered you with my own stupidity :)
martin

Re: DirectoryListing slow?

Please post session log file both from WinSCP GUI and .NET assembly.
t0r3x

DirectoryListing slow?

Hi, first off I would like to say thank you for your explicit documentation and great work on the WinSCP project.

Now, for my problem. I am developing a backup utility in C# which uses a connection over SCP to recover data stored on a NAS Box. My problem at the time being, is that whenever I do a directory listing in WinSCP itself, it is very fast (< 1 sec.), but when I do it with my program, it typically takes about 4-5 seconds. This is not workable for the experience I'm trying to create. Is this a known problem or is there a way to speed things up (except from caching)?

I have pasted the code I am currently using (nothing out of the ordinary I suppose) and have also doublechecked other methods. From the moment I start the thread until it is completed, it takes way to long and it is doing that on ListDirectory. Thanks in advance for your reply.

class WinSCPSession

    {
        #region Fields

        private SessionOptions sessionOptions;
        private string pathToWinSCP;

        #endregion

        public WinSCPSession(SessionOptions sessionOptions, string pathToWinSCP)
        {
            this.sessionOptions = sessionOptions;
            this.pathToWinSCP = pathToWinSCP;
        }

        public void GetDirectoryInfo(object threadItem)
        {
            ThreadInfo threadInfo = (ThreadInfo)threadItem;

            String remotePath = (String)threadInfo.param;
            try
            {
                using (Session session = new Session())
                {
                    session.Open(sessionOptions);
                    session.ExecutablePath = pathToWinSCP;

                    RemoteDirectoryInfo dirInfo = session.ListDirectory(remotePath);

                    AsyncHelper.BeginInvoke(threadInfo.completed, dirInfo.Files);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
    }