1libssh2_sftp_write(3) libssh2 manual libssh2_sftp_write(3)
2
3
4
6 libssh2_sftp_write - write SFTP data
7
9 #include <libssh2.h>
10 #include <libssh2_sftp.h>
11
12 ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
13 const char *buffer,
14 size_t count);
15
17 libssh2_sftp_write(3) writes a block of data to the SFTP server. This
18 method is modeled after the POSIX write() function and uses the same
19 calling semantics.
20
21 handle - SFTP file handle as returned by libssh2_sftp_open_ex(3).
22
23 buffer - points to the data to send off.
24
25 count - Number of bytes from 'buffer' to write. Note that it may not be
26 possible to write all bytes as requested.
27
28 libssh2_sftp_handle(3) will use as much as possible of the buffer and
29 put it into a single SFTP protocol packet. This means that to get maxi‐
30 mum performance when sending larger files, you should try to always
31 pass in at least 32K of data to this function.
32
33
35 Starting in libssh2 version 1.2.8, the default behavior of libssh2 is
36 to create several smaller outgoing packets for all data you pass to
37 this function and it will return a positive number as soon as the first
38 packet is acknowledged from the server.
39
40 This has the effect that sometimes more data has been sent off but
41 isn't acked yet when this function returns, and when this function is
42 subsequently called again to write more data, libssh2 will immediately
43 figure out that the data is already received remotely.
44
45 In most normal situation this should not cause any problems, but it
46 should be noted that if you've once called libssh2_sftp_write() with
47 data and it returns short, you MUST still assume that the rest of the
48 data might've been cached so you need to make sure you don't alter that
49 data and think that the version you have in your next function invoke
50 will be detected or used.
51
52 The reason for this funny behavior is that SFTP can only send 32K data
53 in each packet and it gets all packets acked individually. This means
54 we cannot use a simple serial approach if we want to reach high perfor‐
55 mance even on high latency connections. And we want that.
56
58 Actual number of bytes written or negative on failure.
59
60 If used in non-blocking mode, it returns LIBSSH2_ERROR_EAGAIN when it
61 would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number,
62 it isn't really a failure per se.
63
64 If this function returns 0 (zero) it should not be considered an error,
65 but simply that there was no error but yet no payload data got sent to
66 the other end.
67
69 LIBSSH2_ERROR_ALLOC - An internal memory allocation call failed.
70
71 LIBSSH2_ERROR_SOCKET_SEND - Unable to send data on socket.
72
73 LIBSSH2_ERROR_SOCKET_TIMEOUT -
74
75 LIBSSH2_ERROR_SFTP_PROTOCOL - An invalid SFTP protocol response was
76 received on the socket, or an SFTP operation caused an errorcode to be
77 returned by the server.
78
80 libssh2_sftp_open_ex(3)
81
82
83
84libssh2 0.15 1 Jun 2007 libssh2_sftp_write(3)