|
Lines 75-80
Link Here
|
| 75 |
#define SFTP_EXT_POSIX_RENAME 0x00000001 |
75 |
#define SFTP_EXT_POSIX_RENAME 0x00000001 |
| 76 |
#define SFTP_EXT_STATVFS 0x00000002 |
76 |
#define SFTP_EXT_STATVFS 0x00000002 |
| 77 |
#define SFTP_EXT_FSTATVFS 0x00000004 |
77 |
#define SFTP_EXT_FSTATVFS 0x00000004 |
|
|
78 |
#define SFTP_EXT_FSYNC 0x00000008 |
| 78 |
u_int exts; |
79 |
u_int exts; |
| 79 |
}; |
80 |
}; |
| 80 |
|
81 |
|
|
Lines 352-361
Link Here
|
| 352 |
strcmp(value, "2") == 0) { |
353 |
strcmp(value, "2") == 0) { |
| 353 |
exts |= SFTP_EXT_STATVFS; |
354 |
exts |= SFTP_EXT_STATVFS; |
| 354 |
known = 1; |
355 |
known = 1; |
| 355 |
} if (strcmp(name, "fstatvfs@openssh.com") == 0 && |
356 |
} else if (strcmp(name, "fstatvfs@openssh.com") == 0 && |
| 356 |
strcmp(value, "2") == 0) { |
357 |
strcmp(value, "2") == 0) { |
| 357 |
exts |= SFTP_EXT_FSTATVFS; |
358 |
exts |= SFTP_EXT_FSTATVFS; |
| 358 |
known = 1; |
359 |
known = 1; |
|
|
360 |
} else if (strcmp(name, "fsync@openssh.com") == 0 && |
| 361 |
strcmp(value, "1") == 0) { |
| 362 |
exts |= SFTP_EXT_FSYNC; |
| 363 |
known = 1; |
| 359 |
} |
364 |
} |
| 360 |
if (known) { |
365 |
if (known) { |
| 361 |
debug2("Server supports extension \"%s\" revision %s", |
366 |
debug2("Server supports extension \"%s\" revision %s", |
|
Lines 802-807
Link Here
|
| 802 |
return(status); |
807 |
return(status); |
| 803 |
} |
808 |
} |
| 804 |
|
809 |
|
|
|
810 |
int |
| 811 |
do_fsync(struct sftp_conn *conn, char *handle, u_int handle_len) |
| 812 |
{ |
| 813 |
Buffer msg; |
| 814 |
u_int status, id; |
| 815 |
|
| 816 |
/* Silently return if the extension is not supported */ |
| 817 |
if ((conn->exts & SFTP_EXT_FSYNC) == 0) |
| 818 |
return 0; |
| 819 |
|
| 820 |
buffer_init(&msg); |
| 821 |
|
| 822 |
/* Send fsync request */ |
| 823 |
id = conn->msg_id++; |
| 824 |
|
| 825 |
buffer_put_char(&msg, SSH2_FXP_EXTENDED); |
| 826 |
buffer_put_int(&msg, id); |
| 827 |
buffer_put_cstring(&msg, "fsync@openssh.com"); |
| 828 |
buffer_put_string(&msg, handle, handle_len); |
| 829 |
send_msg(conn->fd_out, &msg); |
| 830 |
debug3("Sent message fsync@openssh.com I:%u", id); |
| 831 |
buffer_free(&msg); |
| 832 |
|
| 833 |
status = get_status(conn->fd_in, id); |
| 834 |
if (status != SSH2_FX_OK) |
| 835 |
error("Couldn't sync file: %s", fx2txt(status)); |
| 836 |
|
| 837 |
return(status); |
| 838 |
} |
| 839 |
|
| 805 |
#ifdef notyet |
840 |
#ifdef notyet |
| 806 |
char * |
841 |
char * |
| 807 |
do_readlink(struct sftp_conn *conn, char *path) |
842 |
do_readlink(struct sftp_conn *conn, char *path) |
|
Lines 924-930
Link Here
|
| 924 |
|
959 |
|
| 925 |
int |
960 |
int |
| 926 |
do_download(struct sftp_conn *conn, char *remote_path, char *local_path, |
961 |
do_download(struct sftp_conn *conn, char *remote_path, char *local_path, |
| 927 |
Attrib *a, int pflag) |
962 |
Attrib *a, int pflag, int sflag) |
| 928 |
{ |
963 |
{ |
| 929 |
Attrib junk; |
964 |
Attrib junk; |
| 930 |
Buffer msg; |
965 |
Buffer msg; |
|
Lines 1153-1158
Link Here
|
| 1153 |
error("Can't set times on \"%s\": %s", |
1188 |
error("Can't set times on \"%s\": %s", |
| 1154 |
local_path, strerror(errno)); |
1189 |
local_path, strerror(errno)); |
| 1155 |
} |
1190 |
} |
|
|
1191 |
/* Flush file to disk if requested */ |
| 1192 |
if (sflag) { |
| 1193 |
debug("syncing \"%s\"", local_path); |
| 1194 |
if (fsync(local_fd) == -1) |
| 1195 |
error("Couldn't sync file \"%s\": %s", |
| 1196 |
local_path, strerror(errno)); |
| 1197 |
} |
| 1156 |
} |
1198 |
} |
| 1157 |
close(local_fd); |
1199 |
close(local_fd); |
| 1158 |
buffer_free(&msg); |
1200 |
buffer_free(&msg); |
|
Lines 1163-1169
Link Here
|
| 1163 |
|
1205 |
|
| 1164 |
static int |
1206 |
static int |
| 1165 |
download_dir_internal(struct sftp_conn *conn, char *src, char *dst, |
1207 |
download_dir_internal(struct sftp_conn *conn, char *src, char *dst, |
| 1166 |
Attrib *dirattrib, int pflag, int printflag, int depth) |
1208 |
Attrib *dirattrib, int pflag, int sflag, int printflag, int depth) |
| 1167 |
{ |
1209 |
{ |
| 1168 |
int i, ret = 0; |
1210 |
int i, ret = 0; |
| 1169 |
SFTP_DIRENT **dir_entries; |
1211 |
SFTP_DIRENT **dir_entries; |
|
Lines 1215-1226
Link Here
|
| 1215 |
strcmp(filename, "..") == 0) |
1257 |
strcmp(filename, "..") == 0) |
| 1216 |
continue; |
1258 |
continue; |
| 1217 |
if (download_dir_internal(conn, new_src, new_dst, |
1259 |
if (download_dir_internal(conn, new_src, new_dst, |
| 1218 |
&(dir_entries[i]->a), pflag, printflag, |
1260 |
&(dir_entries[i]->a), pflag, sflag, printflag, |
| 1219 |
depth + 1) == -1) |
1261 |
depth + 1) == -1) |
| 1220 |
ret = -1; |
1262 |
ret = -1; |
| 1221 |
} else if (S_ISREG(dir_entries[i]->a.perm) ) { |
1263 |
} else if (S_ISREG(dir_entries[i]->a.perm) ) { |
| 1222 |
if (do_download(conn, new_src, new_dst, |
1264 |
if (do_download(conn, new_src, new_dst, |
| 1223 |
&(dir_entries[i]->a), pflag) == -1) { |
1265 |
&(dir_entries[i]->a), pflag, sflag) == -1) { |
| 1224 |
error("Download of file %s to %s failed", |
1266 |
error("Download of file %s to %s failed", |
| 1225 |
new_src, new_dst); |
1267 |
new_src, new_dst); |
| 1226 |
ret = -1; |
1268 |
ret = -1; |
|
Lines 1253-1259
Link Here
|
| 1253 |
|
1295 |
|
| 1254 |
int |
1296 |
int |
| 1255 |
download_dir(struct sftp_conn *conn, char *src, char *dst, |
1297 |
download_dir(struct sftp_conn *conn, char *src, char *dst, |
| 1256 |
Attrib *dirattrib, int pflag, int printflag) |
1298 |
Attrib *dirattrib, int pflag, int sflag, int printflag) |
| 1257 |
{ |
1299 |
{ |
| 1258 |
char *src_canon; |
1300 |
char *src_canon; |
| 1259 |
int ret; |
1301 |
int ret; |
|
Lines 1264-1277
Link Here
|
| 1264 |
} |
1306 |
} |
| 1265 |
|
1307 |
|
| 1266 |
ret = download_dir_internal(conn, src_canon, dst, |
1308 |
ret = download_dir_internal(conn, src_canon, dst, |
| 1267 |
dirattrib, pflag, printflag, 0); |
1309 |
dirattrib, pflag, sflag, printflag, 0); |
| 1268 |
xfree(src_canon); |
1310 |
xfree(src_canon); |
| 1269 |
return ret; |
1311 |
return ret; |
| 1270 |
} |
1312 |
} |
| 1271 |
|
1313 |
|
| 1272 |
int |
1314 |
int |
| 1273 |
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, |
1315 |
do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, |
| 1274 |
int pflag) |
1316 |
int pflag, int sflag) |
| 1275 |
{ |
1317 |
{ |
| 1276 |
int local_fd; |
1318 |
int local_fd; |
| 1277 |
int status = SSH2_FX_OK; |
1319 |
int status = SSH2_FX_OK; |
|
Lines 1445-1450
Link Here
|
| 1445 |
if (pflag) |
1487 |
if (pflag) |
| 1446 |
do_fsetstat(conn, handle, handle_len, &a); |
1488 |
do_fsetstat(conn, handle, handle_len, &a); |
| 1447 |
|
1489 |
|
|
|
1490 |
if (sflag) |
| 1491 |
(void)do_fsync(conn, handle, handle_len); |
| 1492 |
|
| 1448 |
if (do_close(conn, handle, handle_len) != SSH2_FX_OK) |
1493 |
if (do_close(conn, handle, handle_len) != SSH2_FX_OK) |
| 1449 |
status = -1; |
1494 |
status = -1; |
| 1450 |
xfree(handle); |
1495 |
xfree(handle); |
|
Lines 1454-1460
Link Here
|
| 1454 |
|
1499 |
|
| 1455 |
static int |
1500 |
static int |
| 1456 |
upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, |
1501 |
upload_dir_internal(struct sftp_conn *conn, char *src, char *dst, |
| 1457 |
int pflag, int printflag, int depth) |
1502 |
int pflag, int sflag, int printflag, int depth) |
| 1458 |
{ |
1503 |
{ |
| 1459 |
int ret = 0, status; |
1504 |
int ret = 0, status; |
| 1460 |
DIR *dirp; |
1505 |
DIR *dirp; |
|
Lines 1523-1532
Link Here
|
| 1523 |
continue; |
1568 |
continue; |
| 1524 |
|
1569 |
|
| 1525 |
if (upload_dir_internal(conn, new_src, new_dst, |
1570 |
if (upload_dir_internal(conn, new_src, new_dst, |
| 1526 |
pflag, depth + 1, printflag) == -1) |
1571 |
pflag, sflag, depth + 1, printflag) == -1) |
| 1527 |
ret = -1; |
1572 |
ret = -1; |
| 1528 |
} else if (S_ISREG(sb.st_mode)) { |
1573 |
} else if (S_ISREG(sb.st_mode)) { |
| 1529 |
if (do_upload(conn, new_src, new_dst, pflag) == -1) { |
1574 |
if (do_upload(conn, new_src, new_dst, pflag, |
|
|
1575 |
sflag) == -1) { |
| 1530 |
error("Uploading of file %s to %s failed!", |
1576 |
error("Uploading of file %s to %s failed!", |
| 1531 |
new_src, new_dst); |
1577 |
new_src, new_dst); |
| 1532 |
ret = -1; |
1578 |
ret = -1; |
|
Lines 1545-1551
Link Here
|
| 1545 |
|
1591 |
|
| 1546 |
int |
1592 |
int |
| 1547 |
upload_dir(struct sftp_conn *conn, char *src, char *dst, int printflag, |
1593 |
upload_dir(struct sftp_conn *conn, char *src, char *dst, int printflag, |
| 1548 |
int pflag) |
1594 |
int pflag, int sflag) |
| 1549 |
{ |
1595 |
{ |
| 1550 |
char *dst_canon; |
1596 |
char *dst_canon; |
| 1551 |
int ret; |
1597 |
int ret; |
|
Lines 1555-1561
Link Here
|
| 1555 |
return -1; |
1601 |
return -1; |
| 1556 |
} |
1602 |
} |
| 1557 |
|
1603 |
|
| 1558 |
ret = upload_dir_internal(conn, src, dst_canon, pflag, printflag, 0); |
1604 |
ret = upload_dir_internal(conn, src, dst_canon, pflag, sflag, printflag, 0); |
| 1559 |
xfree(dst_canon); |
1605 |
xfree(dst_canon); |
| 1560 |
return ret; |
1606 |
return ret; |
| 1561 |
} |
1607 |
} |