login about faq

Hello Matt,

Can you perhaps look at the performance of SSH/SFTP? This is quick - no complaints about it:

std::auto_ptr<cksftpdir> dirListing(_sftp.ReadDir(handle));
if (dirListing.get()==0) return false;

But after that I loop over the results calling all kind of info-methods for the file/directory.

These are the calls I make (not really in this order and a lot of code removed, only showing the chilkat code without error checking)

long n = dirListing->get_NumFilesAndDirs();
for (int i = 0; i < n; i++) {
std::auto_ptr<cksftpfile> fileObj(dirListing->GetFileObject(i));
if (p_hideSym && fileObj->get_IsSymLink())
if (fileObj->get_IsDirectory())
if (fileObj->get_IsRegular())
ient->_size = fileObj->get_Size64();
CString ux = directoryWeAreListing;
if (ux.Right(1)!=L'/') ux += L'/';
ux += ient->_name;
_sftp.GetFileCreateTime(UTF8(ux), true, false, systime);
_sftp.GetFileLastModified(UTF8(ux), true, false, systime);

I notice for large directory listings, the "ReadDir" is quick enough but the rest of the method seems quite slow. For one or two files this is not a problem, but I am working with directories with thousands of files (and maybe subdirectories).

I wonder if you hit the SFTP server for every (?) call I do in this loop. Or is it the GetFileXXXTime() calls? Can I in someway optimize this, OR CAN YOU?

Thanks for thinking with me, Gert

asked Sep 04 '12 at 23:08

Gert's gravatar image

Gert ♦


The Chilkat.SFtp (CkSFtp) object contains the connection to the SSH server. The Chilkat.SFtpFile (CkSFtpFile) and Chilkat.SFtpDir (CkSFtpDir) objects to not have a connection. Therefore, all methods and properties of the CkSFtpFile and CkSFtpDir objects cannot possibly communicate with the server.

In your code snippet above, the calls to _sftp.GetFileCreateTime and _sftp.GetFileLastModified are sending a message to the server to retrieve the date/times for the path (or handle) specified. You should instead get the file date/time information directly from the fileObj (CkSFtpFile) either through the properties that return a "SYSTEMTIME" or via the methods that return a CkDateTime object.


answered Sep 05 '12 at 07:42

chilkat's gravatar image

chilkat ♦♦


I am not sure why I didnt do that in the first place.


answered Sep 05 '12 at 08:29

Gert's gravatar image

Gert ♦

Stupid me for calling GetFileCreateTime and GetFileLastModified. Now that I have switched to calling those methods on the CkSftpFile performance is great!

Thanks again.


answered Sep 05 '12 at 10:46

Gert's gravatar image

Gert ♦

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Sep 04 '12 at 23:08

Seen: 2,138 times

Last updated: Sep 05 '12 at 10:46

powered by OSQA