Subject: How should my libssh2 program detect when the data upload failed because the destination partition ran out of space?

How should my libssh2 program detect when the data upload failed because the destination partition ran out of space?

From: Jeremy Friesner <jfriesne_at_gmail.com>
Date: Fri, 16 May 2014 15:36:46 -0700

Hi all,

I have a program that uses libssh2 to upload a 152MB file to a partition on a remote machine. In general it works quite well.

The problem I ran into today involves the scenario when there isn't enough drive-space free on the remote machine to hold the entire 152MB file. What I would expect to have happen in this case is for libssh2_channel_write() to return an error-code at some point to indicate the failure, but the behavior I observe instead is that libssh2_channel_write() keeps on behaving normally (i.e. returning positive values or -1/LIBSSH2_ERROR_EGAIN, since I'm using non-blocking I/O), as if the file transfer was working fine.

I'd like to have my program's GUI indicate than an error occurred when this happens -- is there some particular way for me to find out when a file upload has failed due to lack of space (or for any other reason)? For what it's worth, my file transfers use the following sequence of calls (all with the appropriate error checking of the calls' return values, which I've omitted here for clarity);

        _uploadFileChannel = libssh2_scp_send(_session, filePath, permBits, numBytes);
         libssh2_channel_write(_uploadFileChannel, (const char *) firstToSend, numBytesLeft); // called many times, of course
         libssh2_channel_send_eof(_uploadFileChannel);
         libssh2_channel_wait_eof(_uploadFileChannel);
         libssh2_channel_close(_uploadFileChannel);

Btw, just as a sanity check, I ran the built-in scp utility on my Mac to upload a large file to the machine with the full partition:

        jeremy-friesners-mac-pro-3:Downloads jaf$ scp dmitri-6.0.0-2014-05-16-1051-r14027-1-Beta.dmitriUniversalFirmware root_at_msli-dcp-11234772.local.:/mnt/user/
        root_at_msli-dcp-11234772.local.'s password:
        dmitri-6.0.0-2014-05-16-1051-r14027-1-Beta.dmitriUniversalFirmware 100% 152MB 19.0MB/s 00:08
        scp: /mnt/user//dmitri-6.0.0-2014-05-16-1051-r14027-1-Beta.dmitriUniversalFirmware: No space left on device

I note that scp did detect the error, but not until *after* it had already uploaded all 152MB to the server. That seems odd to me, since the destination (/mnt/user) was already completely full, I would expect the error to be reported and the uploaded aborted at the beginning of the transfer rather than at the end. Otherwise, where are all those bytes of data being placed during the upload?

-Jeremy
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2014-05-17