Topic "DirectoryListing slow?"

Author Message
t0r3x
[View user's profile]

Joined: 2012-03-24
Posts: 12
Location: Netherlands
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.

Code:
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);
            }
        }
    }
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Please post session log file both from WinSCP GUI and .NET assembly.
_________________
Martin Prikryl
t0r3x
[View user's profile]

Joined: 2012-03-24
Posts: 12
Location: Netherlands
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 Smile
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License