pscp ls --time-style=long-iso display

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am using pscp in a php program to retrieve some files.
Everything is working fine except that I can't retrieve the list of
file on server as --time-style=long-iso.
The consequence is that I can't always get the time of creation of a
This gives the following output.

-rw-r--r-- 258048 Jul  9 14:15 TTFILE00-3165
-rw-r--r--     62 Jul  9 14:16 TTFILE00-3165.crc
-rw-r--r--  58048 Mar  1  2004 TTFILE00-4110
-rw-r--r--     65 Mar  1  2004 TTFILE00-4110.crc

Under unix I would make
ls -l --time-style=long-iso
which would give me :

-rw-r--r--   258048 2004-07-09 14:15 TTFILE00-3165
-rw-r--r--       62 2004-07-09 14:16 TTFILE00-3165.crc
-rw-r--r--   258048 2004-03-01 15:27 TTFILE00-4110
-rw-r--r--       65 2004-03-01 15:35 TTFILE00-4110.crc

I am trying to modify the code of pscp to manage to send the
--time-style=long-iso information.
I first though it was a very single task as line 2085 (pscp.c)
is :
strcpy(cmd, "ls -la '");
I though I could simply add
strcpy(cmd, "ls -la --time-style=long-iso'");
to the program and the problem would be
unfortunatly this line has absolutly no effect on the program.

After some times, I found that the command to request a list of the
content of a directory is given in function void scp_sftp_listdir(char
*dirname) (line 636 pscp.c).

This function uses a second function fxp_opendir_send(char *path)
(line 585 pscp.c) which at its turn uses the function
sftp_pkt_init(SSH_FXP_OPENDIR) to send the code
#define SSH_FXP_OPENDIR          11    /* 0xb */.

Apparently pscp uses a ssh code (SSH_FXP_OPENDIR 11) to ask the server
to execute a ls.
I did not find any of these code in any ssh explanation.
Does it exist a special SSH code to execute a ls -l
--time-style=long-iso to get the complete time description?


Re: pscp ls --time-style=long-iso display

Quoted text here. Click to load it

Don't know.   Code to do "ls" type stuff looks sometjing like this

If you haven't already got this in your server try adding it as
well as or instead of the SSH_FXP_OPENDIR you've noticed.

#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>

int longlisting(char *d)
DIR *dh;
int ld;
char *dn;
char ldn[2048];
struct dirent *de;
struct stat sb;
time_t t;
struct tm *bt;

if (!d) return (-1);
if (!dh) return (-1);
while ( (de=readdir(dh)) ) {
    dn= de->d_name;
        if ( ((int)ld +  (int)strlen(dn) ) > 2000  ) {
           /* avoid buffer overflows  */
           fprintf(stderr, "LONG NAME - QUITTING\n");
    sprintf(ldn, "%s/%s", d, de->d_name);
    if (0 != lstat(ldn, &sb)) {
        perror("lstat() failed:");
    while (1) {
        if (S_ISREG(sb.st_mode)) {printf("-"); break;}
        if (S_ISDIR(sb.st_mode)) {printf("d"); break;}
        if (S_ISLNK(sb.st_mode)) {printf("l"); break;}
        printf("?");  break;

    /* XXX   Number wants converting to rwxrwxrwx, style */
    printf("%0o ",  sb.st_mode & ~S_IFMT);

    printf("%12d ",  sb.st_size);
    printf("%04d-%02d-%02d %02d:%02d:%02d ",
            1900+bt->tm_year, 1+bt->tm_mon, bt->tm_mday,
            bt->tm_hour, bt->tm_min, bt->tm_sec );
    printf("%s\n", dn );

int main()

Elvis Notargiacomo  master AT barefaced DOT cheek /
    7.031: OnACPower returned value( 0x1 ) which is Equal To 0x1

Re: pscp ls --time-style=long-iso display

Hi Elvis,

Thanks for you long answer.
Unfortunatly I do not have access to the server which is on our
customer side.
But I will have a look to the code of our own server, just to see if I
could have done the change.

Thanks for your help.


Re: pscp ls --time-style=long-iso display

Why not just use ssh to execute the ls command you want on the remote
side, rather using the sftp protocol?

  Richard Silverman

Re: pscp ls --time-style=long-iso display

Hi Richard,

This was my first idea, but then as I work in windows I just found pscp
as ssh client to be able to access my files on the server.

Do you have any other solution than pscp to ssh from windows?

I looked to the openssh site and had a look at what they have in
section "alternative for windows". Unfortunatly most of the programs
require cygwin. I hope to not have to install the complete cygwin to
just be able to do my ls.

Thanks for your time.

Emmanuel Charruau

Re: pscp ls --time-style=long-iso display

Quoted text here. Click to load it

PSCP supports two methods of performing file operations: SCP (the older
and simpler method) and SFTP (the newer method, which is used by default
if possible). When in SCP mode, "pscp -ls" just performs an "ls" command
on the server; scp_sftp_listdir() and SSH_FXP_OPENDIR is part of the
procedure for fetching a list of files with SFTP.

You can force a particular backend with the "-scp" and "-sftp" options;
if you use "-scp" (and the server supports your "--time-style" option)
you should find that your change becomes effective.

Quoted text here. Click to load it

(Note that this is a much newer version of the protocol spec than PuTTY
supports, and cannot be used to fully understand the implementation in
PSCP/PSFTP due to protocol changes.)

Quoted text here. Click to load it


("pscp -ls" in SFTP mode uses the "longname" field returned by the SFTP
server, and there's no way of requesting a particular format for that;
there's no need, as if a particular field or format is required it is
returned in a machine-readable form alongside the textual "longname"
field, and can be output in whatever format is desired. We will probably
have to do this at some point in any case, as more recent versions of
the SFTP protocol have dropped the "longname" field.)

Re: pscp ls --time-style=long-iso display

Hi Jacob,

I put the option -scp like you said and it just works perfectly.
I have now my long date representation and can extract the time for
every file :).

I would have a question now. I just read again the pscp documentation
and did not find how pscp can give me the machine-readable value from
which I could extract all the date, time, and size info (that would be
even better than parsing the directory properties).

Thanks a lot for your long and detailed explanation. This was really



Jacob Nevins wrote:
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it

Site Timeline