1libssh2_sftp_write(3)               libssh2              libssh2_sftp_write(3)
2
3
4

NAME

6       libssh2_sftp_write - write SFTP data
7

SYNOPSIS

9       #include <libssh2.h>
10       #include <libssh2_sftp.h>
11
12       ssize_t
13       libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
14                          const char *buffer,
15                          size_t count);
16

DESCRIPTION

18       libssh2_sftp_write(3)  writes  a block of data to the SFTP server. This
19       method is modeled after the POSIX write() function and  uses  the  same
20       calling semantics.
21
22       handle - SFTP file handle as returned by libssh2_sftp_open_ex(3).
23
24       buffer - points to the data to send off.
25
26       count - Number of bytes from 'buffer' to write. Note that it may not be
27       possible to write all bytes as requested.
28
29       libssh2_sftp_handle(3) will use as much as possible of the  buffer  and
30       put it into a single SFTP protocol packet. This means that to get maxi‐
31       mum performance when sending larger files, you  should  try  to  always
32       pass in at least 32K of data to this function.
33

WRITE AHEAD

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  is
41       not  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 have once called libssh2_sftp_write()  with
47       data  and  it returns short, you MUST still assume that the rest of the
48       data might have been cached so you need to make sure you do  not  alter
49       that data and think that the version you have in your next function in‐
50       voke 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

RETURN VALUE

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 is not really a failure per se.
63
64       If this function returns 0 (zero) it should not be considered an error,
65       but that there was no error but yet no payload data  got  sent  to  the
66       other end.
67

ERRORS

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 re‐
76       ceived on the socket, or an SFTP operation caused an  errorcode  to  be
77       returned by the server.
78

SEE ALSO

80       libssh2_sftp_open_ex(3)
81
82
83
84libssh2 0.15                      1 Jun 2007             libssh2_sftp_write(3)
Impressum