Subject: Re: libssh2_sftp_stat_ex returns zero filesize

Re: libssh2_sftp_stat_ex returns zero filesize

From: Dan Hayes <dhayes_at_capmarktech.com>
Date: Tue, 13 Dec 2011 21:44:26 -0500

Below is the trace excerpt picking up where I successfully executed
libssh2_sftp_open() command and then issued the stat command. You'll
notice the file name is:

/ADT00359/%25ADT00359%25ADT00359%25null%25DONE%25dmh_65l1h3006gntl7mu00027jpn

The file name has embedded % which I have expanded to their hexadecimal
representation (%25). The program has not problem with opening this file
and successfully reading the contents. For some reason it cannot return
the actual file size.

<-------------BEGIN EXCERPT ---------------------->
[libssh2] 1.948061 SFTP: Open command successful
libssh2_sftp_open() is done, get file information
[libssh2] 1.948083 SFTP: LStatting
/ADT00359/%25ADT00359%25ADT00359%25null%25DONE%25dmh_65l1h3006gntl7mu00027jpn
[libssh2] 1.948089 Conn: Writing 90 bytes on channel 0/0, stream #0
[libssh2] 1.948096 Conn: Sending 90 bytes on channel 0/0, stream_id=0
=> libssh2_transport_write plain (9 bytes)
0000: 5E 00 00 00 00 00 00 00 5A : ^.......Z
=> libssh2_transport_write plain2 (90 bytes)
0000: 00 00 00 56 07 00 00 00 01 00 00 00 4D 2F 41 44 : ...V........M/AD
0010: 54 30 30 33 35 39 2F 25 32 35 41 44 54 30 30 33 : T00359/%25ADT003
0020: 35 39 25 32 35 41 44 54 30 30 33 35 39 25 32 35 : 59%25ADT00359%25
0030: 6E 75 6C 6C 25 32 35 44 4F 4E 45 25 32 35 64 6D : null%25DONE%25dm
0040: 68 5F 36 35 6C 31 68 33 30 30 36 67 6E 74 6C 37 : h_65l1h3006gntl7
0050: 6D 75 30 30 30 32 37 6A 70 6E : mu00027jpn
[libssh2] 1.948284 Socket: Sent 132/132 bytes at 0x91f2600
=> libssh2_transport_write send() (132 bytes)
0000: 78 7A A1 29 B2 EB 2B 59 14 AA 64 C5 B3 5A 6F E0 : xz.)..+Y..d..Zo.
0010: 9E 08 AB BB 4B 29 E9 FE 47 55 FA 76 94 EE 26 F6 : ....K)..GU.v..&.
0020: 57 75 85 9C 91 A4 81 E6 09 C2 2F 25 0E B4 2E 9A : Wu......../%....
0030: ED 21 7B 18 19 46 24 7C BF A5 32 0E C2 06 42 BA : .!{..F$|..2...B.
0040: 4A 7A B9 CD 9E 2A 4B E6 62 77 9D 38 1B D2 73 1E : Jz...*K.bw.8..s.
0050: 2A 78 E9 59 12 4D C4 95 34 FE 5B 05 60 CB 07 6A : *x.Y.M..4.[.`..j
0060: B7 12 91 76 E4 BA AB 8F 20 D0 C1 3A F8 1C 3A E3 : ...v.... ..:..:.
0070: 14 7E C5 F2 3D 5F 37 FD 5C 17 7B 62 92 5D D9 62 : .~..=_7.\.{b.].b
0080: 26 8F 58 D2 : &.X.
[libssh2] 1.948322 SFTP: recv packet
[libssh2] 1.948328 Failure Event: -37 - would block
[libssh2] 2.065154 SFTP: recv packet
[libssh2] 2.065196 Conn: channel_read() wants 4 bytes from channel 0/0
stream #0
[libssh2] 2.065228 Socket: Recved 68/16384 bytes to 0x91ee5d8+0
=> libssh2_transport_read() raw (68 bytes)
0000: 51 46 78 B8 43 3B B0 F0 1D F5 C2 1F 36 1F 98 38 : QFx.C;......6..8
0010: B1 9E 6A 11 49 07 27 D2 32 A4 6B 9B 4B DF F3 C4 : ..j.I.'.2.k.K...
0020: 29 AA B6 35 C2 81 0C 5D E9 AE 39 68 87 35 1F AE : )..5...]..9h.5..
0030: F1 46 A5 5C 93 F5 A7 19 F9 5C CE 4A 66 60 16 CE : .F.\.....\.Jf`..
0040: B5 A6 FA 0E : ....
=> libssh2_transport_read() plain (34 bytes)
0000: 5E 00 00 00 00 00 00 00 19 00 00 00 15 69 00 00 : ^............i..
0010: 00 01 00 00 00 0C 00 00 81 80 4E E8 0A 95 4E E8 : ..........N...N.
0020: 0A 95 : ..
[libssh2] 2.065325 Transport: Packet type 94 received, length=34
[libssh2] 2.065334 Conn: 25 bytes packet_add() for 0/0/0
[libssh2] 2.065345 Conn: channel_read() got 4 of data from 0/0/0
[libssh2] 2.065352 SFTP: Data begin - Packet Length: 21
[libssh2] 2.065360 Conn: channel_read() got 21 of data from 0/0/0 [ul]
[libssh2] 2.065367 SFTP: Received packet 105 (len 21)
Stat Data: RetCode=0
Stat Data: Size=0
Stat Data: Perm=8180
Stat Data: mtime=1323829909
Stat Data: mtime=Wed Dec 14 02:31:49 2011

libssh2_sftp_read()!

<------END EXCERPT--------------->

The interesting lines of the program (basically example/sftp.c) which are
generating this output are:

    sftp_handle =
        libssh2_sftp_open(sftp_session, sftppath, LIBSSH2_FXF_READ, 0);

    if (!sftp_handle) {
        fprintf(stderr, "Unable to open file with SFTP: %ld\n",
                libssh2_sftp_last_error(sftp_session));
        goto shutdown;
    }
    fprintf(stderr, "libssh2_sftp_open() is done, get file information\n");
    LIBSSH2_SFTP_ATTRIBUTES attrs;
    rc = libssh2_sftp_stat_ex(sftp_session, sftppath, strlen(sftppath),
LIBSSH2_SFTP_LSTAT, &attrs );
    if (rc<0)
    {
        fprintf(stderr, "error trying to fstat_ex, returned %d\n", rc);
    }
    else
    {
        fprintf(stderr, "Stat Data: RetCode=%d\n", rc);
        fprintf(stderr, "Stat Data: Size=%llu\n", attrs.filesize);
        fprintf(stderr, "Stat Data: Perm=%lx\n", attrs.permissions);
        fprintf(stderr, "Stat Data: mtime=%lu\n", attrs.mtime);
        fprintf(stderr, "Stat Data: mtime=%s\n",
 asctime(localtime(&attrs.mtime)));
    }

On Tue, Dec 13, 2011 at 6:49 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Tue, 13 Dec 2011, Dan Hayes wrote:
>
> Any insight would be most appreciated.
>>
>
> Two ideas:
>
> 1 - provide trace oututs showing what the protocol is doing:
>
> libssh2_trace(session, ~0);
>
> 2 - provide us source code to an example that repeats the problem for you,
> as
> then it'll be easier for us to test and see how the same thing works for
> us!
>
> --
>
> / daniel.haxx.se
> ______________________________**_________________
> libssh2-devel http://cool.haxx.se/cgi-bin/**mailman/listinfo/libssh2-devel<http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel>
>

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-12-14