[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sftp_write failure question
[Thread Prev] | [Thread Next]
- Subject: Re: sftp_write failure question
- From: Jakub Jelen <jjelen@xxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Tue, 16 Jul 2024 09:42:37 +0200
- To: libssh@xxxxxxxxxx
- Cc: "reid.thompson" <reid.thompson@xxxxxxxxxxxxxxx>
Hi, what version of libssh do you use? The sftp reads and writes are capped to some size, which is reported by limits@xxxxxxxxxxx SFTP extension and which might differ between read and write https://github.com/openssh/openssh-portable/commit/788cbc5b74a53956ba9fff11e1ca506271a3597f The value 262120 is clearly over the 256*1024-1024, which is max write size in OpenSSH sftp server reported by limits: https://github.com/openssh/openssh-portable/blob/master/sftp-server.c#L1542 The latest version (master and soon to be released 0.11) should already handle this and not attempt to write more than limits. In any case, if you are writing some new application using SFTP, I can recommend you to have a look into the new async SFTP, which should provide much better throughput (available in master and soon-to-be-released 0.11): https://api.libssh.org/master/libssh_tutor_sftp_aio.html Jakub On Tue, Jul 16, 2024 at 2:31 AM <reid.thompson@xxxxxxxxxxxxxxx> wrote: > > with code of the format below ( pulled from the examples ) where source > is say 75MB in size. > > ...snip... > while ((len = sftp_read(source, data, 4096)) > 0) { > if (sftp_write(to, data, len) != len) { > fprintf(stderr, "Error writing %d bytes: %s\n", > len, ssh_get_error(session)); > sftp_close(to); > sftp_close(fichier); > goto end; > } > } > ...snip... > > read/write will successfully transfer the complete file. > > if the code is altered to > > ...snip... > BUF_SIZE=xxxxx > char data[BUF_SIZE] = {0}; > ... > while ((len = sftp_read(source, data, BUF_SIZE)) > 0) { > if (sftp_write(to, data, len) != len) { > fprintf(stderr, "Error writing %d bytes: %s\n", > len, ssh_get_error(session)); > sftp_close(to); > sftp_close(fichier); > goto end; > } > } > ...snip... > > read/write will succeed until the value of BUF_SIZE is set to 262120 or > greater. > at which point sftp_write will write BUF_SIZE and sftp_packet_read will > fail with "Received EOF while reading sftp packet size" and the SFTP > server will log a bad message error: > "Jul 15 17:28:28 endpoint sftp-server[1537206]: error: bad message from 100.98.195.26 local user rthompso" > > Is this expected/is this an internal limit to the amount that can be > written per invocation? > Is there a way to increase the amount of data that can be successfully > written per invocation? > > > Thanks, > Reid > > >
sftp_write failure question | reid.thompson@xxxxxxxxxxxxxxx |