[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sftp_read receives EOF on second call for a 24kb file


Hi,

I think we had an htonll implementation already (I remember having
written it).
I also don't understand the point of the int num = 42; etc.
That's just a runtime check to do something if we are in little-endian,
and this inside a #ifdef WORDS_BIGENDIAN. Is there any chance that this
could be defined on a little endian machine ?

Aris

Le 24/10/13 21:07, Kevin Lambert a écrit :
> I have found that Darren’s cmake build of 0.5.5 libssh.dll via mingw32
> works fine for me whereas my build using MSVC 2005 32bit is causing a
> problem.  Two things I had to do to get sftp.c to build were:
> 
>  
> 
> 1.       define htonll as below
> 
> 2.       comment out line 292 /#ifndef HAVE_NTOHLL/ and /#endif /*
> HAVE_NTOHLL *// in misc.c to get sftp.c to build.
> 
>  
> 
> uint64_t htonll(uint64_t value) {
> 
> #ifdefWORDS_BIGENDIAN
> 
>     int num = 42;
> 
>     if (*(char *)&num == 42) {
> 
>         uint32_t high_part = htonl((uint32_t)(value >> 32));
> 
>         uint32_t low_part = htonl((uint32_t)(value & 0xFFFFFFFFLL));
> 
>         return (((uint64_t)low_part) << 32) | high_part;
> 
>     } else {
> 
>         return value;
> 
>     }
> 
> #else
> 
>   return value;
> 
> #endif/* WORDS_BIGENDIAN */
> 
>  
> 
> Was anybody able to get sftp.c to build under MSVC 2005 without making
> these two changes?
> 
>  
> 
> Kevin
> 
>  
> 
> *From:*Darren [mailto:d.tomlin@xxxxxxxxxxxx]
> *Sent:* Wednesday, October 23, 2013 9:20 AM
> *To:* libssh@xxxxxxxxxx
> *Subject:* Re: sftp_read receives EOF on second call for a 24kb file
> 
>  
> 
>  
> 
> Hi Andreas :o),
> 
> Many thanks for LibSSH!
> 
> Alas, I believe it is a bug in libssh which is why I came up with that
> work around.
> 
>  I know it's not a great solution but it does work for the time being ;)
> 
> -Darren.
> 
>  
> 
> -----Original Message-----
> From: Kevin Lambert <klambert@xxxxxxxxx <mailto:klambert@xxxxxxxxx>>
> To: libssh@xxxxxxxxxx <mailto:libssh@xxxxxxxxxx>
> Sent: Wed, 23 Oct 2013 13:33
> Subject: RE: sftp_read receives EOF on second call for a 24kb file
> 
> That is what I was asking about.  I have a 24kb file that I was trying to 
> 
> transfer in 1kb chunks, transferred 1kb without a problem but on my second call 
> 
> to sftp_read there was a SSH_FX_EOF received at line 1802 in sftp.c (version 
> 
> 0.5.5).  I built this with openssl 1.0.1.  The reason I sent the ssh_session 
> 
> init along with the sftp code was incase there was something I was doing wrong 
> 
> in the ssh session initialization to cause this.
> 
>  
> 
> My read loop is as such:
> 
>  
> 
>   char buffer[1024];
> 
>   size_t length = sizeof(buffer);
> 
>   size_t totalLength = 0;
> 
>     size_t count = 0;
> 
>  
> 
>     count = sftp_read(file, buffer, length);
> 
>  
> 
>     while ( count > 0 ) {
> 
>  
> 
>       if ( destFile.is_open() ) {
> 
>         destFile.write(buffer, length);
> 
>       }
> 
>  
> 
>       totalLength += count;
> 
>  
> 
>       count = sftp_read(file, buffer, length);
> 
>     }
> 
>  
> 
> Kevin
> 
>  
> 
> -----Original Message-----
> 
> From: Aris Adamantiadis [mailto:aris@xxxxxxxxxxxx <mailto:aris@xxxxxxxxxxxx?>] 
> 
> Sent: Wednesday, October 23, 2013 7:47 AM
> 
> To: libssh@xxxxxxxxxx <mailto:libssh@xxxxxxxxxx>
> 
> Subject: Re: sftp_read receives EOF on second call for a 24kb file
> 
>  
> 
> Hi Andreas,
> 
>  
> 
> I think Kevin complained that sftp_read returned an EOF condition when the file 
> 
> was not fully read, and if it does it's a bug in libssh.
> 
>  
> 
> Aris
> 
>  
> 
> Le 23/10/13 09:53, Andreas Schneider a écrit :
> 
>> On Tuesday 22 October 2013 18:58:17 Darren wrote:
> 
>>>  Hi Kevin,
> 
>>> 
> 
>>> Assuming remote to local transfer:
> 
>>> 
> 
>>> You read the first chunk of data, and use sftp_seek to move the file 
> 
>>> pointer
> 
>>> 
> 
>> 
> 
>> There is absolutely no need to call sftp_seek() you only need it if 
> 
>> you resume a transfer. The API works the same way as the POSIX API. 
> 
>> Files should be transferred in small chunks.
> 
>> 
> 
>> #define MAX_XFER_BUF_SIZE 16384
> 
>> 
> 
>> char buf[MAX_XFER_BUF_SIZE];
> 
>> 
> 
>> file = sftp_open(sftp, path, O_RDONLY, 0);
> 
>> 
> 
>> for (;;) {
> 
>>       bytesread = sftp_read(file, buf, MAX_XFER_BUF_SIZE);
> 
>>       if (bytesread == 0) {
> 
>>              break; /* EOF */
> 
>>       } else if (bytesread < 0) {
> 
>>              /* ERROR HANDLING */
> 
>>       }
> 
>> 
> 
>>       byteswritten = write(fd, buf, MAX_XFER_BUF_SIZE)
> 
>>       if (byteswritten != bytesread) {
> 
>>               /* ERROR */
> 
>>       }
> 
>> }
> 
>> 
> 
>> This way I can transfer files which are several gigabyte of size.
> 
>> 
> 
>> 
> 
>>       -- andreas
> 
>> 
> 
>  
> 
>  
> 
>  
> 

References:
RE: sftp_read receives EOF on second call for a 24kb file"Kevin Lambert" <klambert@xxxxxxxxx>
Re: sftp_read receives EOF on second call for a 24kb fileDarren <d.tomlin@xxxxxxxxxxxx>
RE: sftp_read receives EOF on second call for a 24kb file"Kevin Lambert" <klambert@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org