/* XXX: copy between two remote sites */
#include "includes.h"
-RCSID("$OpenBSD: sftp-client.c,v 1.53 2005/03/10 22:01:05 deraadt Exp $");
+RCSID("$OpenBSD: sftp-client.c,v 1.60 2006/02/20 17:19:54 stevesk Exp $");
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_STAT_H
+# include <sys/stat.h>
+#endif
+# include <signal.h>
#include "openbsd-compat/sys-queue.h"
extern volatile sig_atomic_t interrupted;
extern int showprogress;
-/* Minimum amount of data to read at at time */
+/* Minimum amount of data to read at a time */
#define MIN_READ_SIZE 512
-/* Maximum packet size */
-#define MAX_MSG_LENGTH (256 * 1024)
-
struct sftp_conn {
int fd_in;
int fd_out;
{
u_char mlen[4];
- if (buffer_len(m) > MAX_MSG_LENGTH)
+ if (buffer_len(m) > SFTP_MAX_MSG_LENGTH)
fatal("Outbound message too long %u", buffer_len(m));
/* Send length first */
PUT_32BIT(mlen, buffer_len(m));
- if (atomicio(vwrite, fd, mlen, sizeof(mlen)) <= 0)
+ if (atomicio(vwrite, fd, mlen, sizeof(mlen)) != sizeof(mlen))
fatal("Couldn't send packet: %s", strerror(errno));
- if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) <= 0)
+ if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) != buffer_len(m))
fatal("Couldn't send packet: %s", strerror(errno));
buffer_clear(m);
static void
get_msg(int fd, Buffer *m)
{
- ssize_t len;
u_int msg_len;
buffer_append_space(m, 4);
- len = atomicio(read, fd, buffer_ptr(m), 4);
- if (len == 0)
- fatal("Connection closed");
- else if (len == -1)
- fatal("Couldn't read packet: %s", strerror(errno));
+ if (atomicio(read, fd, buffer_ptr(m), 4) != 4) {
+ if (errno == EPIPE)
+ fatal("Connection closed");
+ else
+ fatal("Couldn't read packet: %s", strerror(errno));
+ }
msg_len = buffer_get_int(m);
- if (msg_len > MAX_MSG_LENGTH)
+ if (msg_len > SFTP_MAX_MSG_LENGTH)
fatal("Received message too long %u", msg_len);
buffer_append_space(m, msg_len);
- len = atomicio(read, fd, buffer_ptr(m), msg_len);
- if (len == 0)
- fatal("Connection closed");
- else if (len == -1)
- fatal("Read packet: %s", strerror(errno));
+ if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) {
+ if (errno == EPIPE)
+ fatal("Connection closed");
+ else
+ fatal("Read packet: %s", strerror(errno));
+ }
}
static void
SFTP_DIRENT ***dir)
{
Buffer msg;
- u_int type, id, handle_len, i, expected_id, ents = 0;
+ u_int count, type, id, handle_len, i, expected_id, ents = 0;
char *handle;
id = conn->msg_id++;
}
for (; !interrupted;) {
- int count;
-
id = expected_id = conn->msg_id++;
debug3("Sending SSH2_FXP_READDIR I:%u", id);
Attrib junk, *a;
Buffer msg;
char *handle;
- int local_fd, status, num_req, max_req, write_error;
+ int local_fd, status = 0, write_error;
int read_error, write_errno;
u_int64_t offset, size;
- u_int handle_len, mode, type, id, buflen;
+ u_int handle_len, mode, type, id, buflen, num_req, max_req;
off_t progress_counter;
struct request {
u_int id;
goto done;
}
debug3("In write loop, ack for %u %u bytes at %llu",
- ack->id, ack->len, (unsigned long long)ack->offset);
+ ack->id, ack->len, (unsigned long long)ack->offset);
++ackid;
xfree(ack);
}