version 1.114, 2014/01/31 16:39:19 |
version 1.115, 2014/04/21 14:36:16 |
|
|
|
|
int |
int |
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, |
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, |
int preserve_flag, int fsync_flag) |
int preserve_flag, int resume, int fsync_flag) |
{ |
{ |
int local_fd; |
int local_fd; |
int status = SSH2_FX_OK; |
int status = SSH2_FX_OK; |
|
|
char *handle, *data; |
char *handle, *data; |
Buffer msg; |
Buffer msg; |
struct stat sb; |
struct stat sb; |
Attrib a; |
Attrib a, *c = NULL; |
u_int32_t startid; |
u_int32_t startid; |
u_int32_t ackid; |
u_int32_t ackid; |
struct outstanding_ack { |
struct outstanding_ack { |
|
|
if (!preserve_flag) |
if (!preserve_flag) |
a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME; |
a.flags &= ~SSH2_FILEXFER_ATTR_ACMODTIME; |
|
|
|
if (resume) { |
|
/* Get remote file size if it exists */ |
|
if ((c = do_stat(conn, remote_path, 0)) == NULL) { |
|
close(local_fd); |
|
return -1; |
|
} |
|
|
|
if ((off_t)c->size >= sb.st_size) { |
|
error("destination file bigger or same size as " |
|
"source file"); |
|
close(local_fd); |
|
return -1; |
|
} |
|
|
|
if (lseek(local_fd, (off_t)c->size, SEEK_SET) == -1) { |
|
close(local_fd); |
|
return -1; |
|
} |
|
} |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
|
|
/* Send open request */ |
/* Send open request */ |
|
|
buffer_put_char(&msg, SSH2_FXP_OPEN); |
buffer_put_char(&msg, SSH2_FXP_OPEN); |
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_cstring(&msg, remote_path); |
buffer_put_cstring(&msg, remote_path); |
buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC); |
buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT| |
|
(resume ? SSH2_FXF_APPEND : SSH2_FXF_TRUNC)); |
encode_attrib(&msg, &a); |
encode_attrib(&msg, &a); |
send_msg(conn, &msg); |
send_msg(conn, &msg); |
debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path); |
debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path); |
|
|
data = xmalloc(conn->transfer_buflen); |
data = xmalloc(conn->transfer_buflen); |
|
|
/* Read from local and write to remote */ |
/* Read from local and write to remote */ |
offset = progress_counter = 0; |
offset = progress_counter = (resume ? c->size : 0); |
if (showprogress) |
if (showprogress) |
start_progress_meter(local_path, sb.st_size, |
start_progress_meter(local_path, sb.st_size, |
&progress_counter); |
&progress_counter); |
|
|
|
|
static int |
static int |
upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth, |
upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, int depth, |
int preserve_flag, int print_flag, int fsync_flag) |
int preserve_flag, int print_flag, int resume, int fsync_flag) |
{ |
{ |
int ret = 0, status; |
int ret = 0, status; |
DIR *dirp; |
DIR *dirp; |
|
|
continue; |
continue; |
|
|
if (upload_dir_internal(conn, new_src, new_dst, |
if (upload_dir_internal(conn, new_src, new_dst, |
depth + 1, preserve_flag, print_flag, |
depth + 1, preserve_flag, print_flag, resume, |
fsync_flag) == -1) |
fsync_flag) == -1) |
ret = -1; |
ret = -1; |
} else if (S_ISREG(sb.st_mode)) { |
} else if (S_ISREG(sb.st_mode)) { |
if (do_upload(conn, new_src, new_dst, |
if (do_upload(conn, new_src, new_dst, |
preserve_flag, fsync_flag) == -1) { |
preserve_flag, resume, fsync_flag) == -1) { |
error("Uploading of file %s to %s failed!", |
error("Uploading of file %s to %s failed!", |
new_src, new_dst); |
new_src, new_dst); |
ret = -1; |
ret = -1; |
|
|
|
|
int |
int |
upload_dir(struct sftp_conn *conn, char *src, char *dst, int preserve_flag, |
upload_dir(struct sftp_conn *conn, char *src, char *dst, int preserve_flag, |
int print_flag, int fsync_flag) |
int print_flag, int resume, int fsync_flag) |
{ |
{ |
char *dst_canon; |
char *dst_canon; |
int ret; |
int ret; |
|
|
} |
} |
|
|
ret = upload_dir_internal(conn, src, dst_canon, 0, preserve_flag, |
ret = upload_dir_internal(conn, src, dst_canon, 0, preserve_flag, |
print_flag, fsync_flag); |
print_flag, resume, fsync_flag); |
|
|
free(dst_canon); |
free(dst_canon); |
return ret; |
return ret; |