login about faq

Is there a way with the opendir/read listing to return the data from oldest to newest? I am using the perl chilkat library.

asked Feb 11 at 09:32

skingsbury's gravatar image


You should be able to send a raw command to do that. I think there is a SendCommand method and the Quote would also do that. ls

But it looks like the FTP protocol does not support options. SFTP docs allow options on the ls command.



answered Feb 11 at 16:08

cdlvj130's gravatar image


SFTP does not have quote or send command method.

This is how I do it. Get your list and then return a associative array which can be sorted. The problem is you have to have similar routines because servers on the other end do not behave the same way. Especially if you are working with a mainframe on the other end. Do not remember but that associate array is probably already in order.

ie $rlist{"filename.txt"} = "20160211020250"

   $dirListing = $ftp->ReadDir($handle);

$num = $dirListing->get_NumFilesAndDirs(); if ($num < 0) { $message="listDirectory:Error [$!]n" . $ftp->lastErrorText(); $cm->Comment($message,1); return ($message); } if ($num > 0) { for ($rc=0; $rc <= $num - 1; $rc++) { $fileObj = $dirListing->GetFileObject($rc); $file = $fileObj->filename();

       if (!$fileObj->get_IsDirectory())
          $file =~ s!\/!!;
          $tm = $fileObj->get_LastModifiedTime($timed);
          $ftime = sprintf "%04d%02d%02d%02d%02d%02d",$timed->{wYear},$timed->{wMonth},$timed->{wDay},$timed->{wHour},$timed->{wMinute},$timed->{wSecond};
          $rlist{$file} = $ftime;

} $cm->Comment("readDirectory:OK [$dir]",1); return %rlist;


answered Feb 12 at 09:56

cdlvj130's gravatar image


edited Feb 12 at 10:00

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: Feb 11 at 09:32

Seen: 769 times

Last updated: Feb 12 at 10:00

powered by OSQA