| ︙ | | | ︙ | |
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
|
char buf[80];
sprintf(buf, "T%lu 0 %lu 0\n", mtime, atime);
back->send(backhandle, buf, strlen(buf));
return response();
}
}
int scp_send_filename(char *name, uint64 size, int modes)
{
if (using_sftp) {
char *fullname;
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
if (scp_sftp_targetisdir) {
fullname = dupcat(scp_sftp_remotepath, "/", name, NULL);
} else {
fullname = dupstr(scp_sftp_remotepath);
}
sftp_register(req = fxp_open_send(fullname, SSH_FXF_WRITE |
SSH_FXF_CREAT | SSH_FXF_TRUNC));
rreq = sftp_find_request(pktin = sftp_recv());
assert(rreq == req);
scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
if (!scp_sftp_filehandle) {
tell_user(stderr, "pscp: unable to open %s: %s",
fullname, fxp_error());
errs++;
return 1;
}
scp_sftp_fileoffset = uint64_make(0, 0);
scp_sftp_xfer = xfer_upload_init(scp_sftp_filehandle,
scp_sftp_fileoffset);
sfree(fullname);
return 0;
} else {
char buf[40];
char sizestr[40];
uint64_decimal(size, sizestr);
sprintf(buf, "C%04o %s ", modes, sizestr);
back->send(backhandle, buf, strlen(buf));
back->send(backhandle, name, strlen(name));
back->send(backhandle, "\n", 1);
return response();
}
}
|
|
>
>
>
>
|
>
>
>
|
|
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
|
char buf[80];
sprintf(buf, "T%lu 0 %lu 0\n", mtime, atime);
back->send(backhandle, buf, strlen(buf));
return response();
}
}
int scp_send_filename(char *name, uint64 size, int permissions)
{
if (using_sftp) {
char *fullname;
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
struct fxp_attrs attrs;
if (scp_sftp_targetisdir) {
fullname = dupcat(scp_sftp_remotepath, "/", name, NULL);
} else {
fullname = dupstr(scp_sftp_remotepath);
}
attrs.flags = 0;
PUT_PERMISSIONS(attrs, permissions);
sftp_register(req = fxp_open_send(fullname, SSH_FXF_WRITE |
SSH_FXF_CREAT | SSH_FXF_TRUNC,
&attrs));
rreq = sftp_find_request(pktin = sftp_recv());
assert(rreq == req);
scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
if (!scp_sftp_filehandle) {
tell_user(stderr, "pscp: unable to open %s: %s",
fullname, fxp_error());
errs++;
return 1;
}
scp_sftp_fileoffset = uint64_make(0, 0);
scp_sftp_xfer = xfer_upload_init(scp_sftp_filehandle,
scp_sftp_fileoffset);
sfree(fullname);
return 0;
} else {
char buf[40];
char sizestr[40];
uint64_decimal(size, sizestr);
if (permissions < 0)
permissions = 0644;
sprintf(buf, "C%04o %s ", (int)(permissions & 07777), sizestr);
back->send(backhandle, buf, strlen(buf));
back->send(backhandle, name, strlen(name));
back->send(backhandle, "\n", 1);
return response();
}
}
|
| ︙ | | | ︙ | |
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
|
#define SCP_SINK_DIR 2
#define SCP_SINK_ENDDIR 3
#define SCP_SINK_RETRY 4 /* not an action; just try again */
struct scp_sink_action {
int action; /* FILE, DIR, ENDDIR */
char *buf; /* will need freeing after use */
char *name; /* filename or dirname (not ENDDIR) */
int mode; /* access mode (not ENDDIR) */
uint64 size; /* file size (not ENDDIR) */
int settime; /* 1 if atime and mtime are filled */
unsigned long atime, mtime; /* access times for the file */
};
int scp_get_sink_action(struct scp_sink_action *act)
{
|
|
|
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
|
#define SCP_SINK_DIR 2
#define SCP_SINK_ENDDIR 3
#define SCP_SINK_RETRY 4 /* not an action; just try again */
struct scp_sink_action {
int action; /* FILE, DIR, ENDDIR */
char *buf; /* will need freeing after use */
char *name; /* filename or dirname (not ENDDIR) */
long permissions; /* access permissions (not ENDDIR) */
uint64 size; /* file size (not ENDDIR) */
int settime; /* 1 if atime and mtime are filled */
unsigned long atime, mtime; /* access times for the file */
};
int scp_get_sink_action(struct scp_sink_action *act)
{
|
| ︙ | | | ︙ | |
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
|
if (newitem->wildcard) {
act->action = SCP_SINK_RETRY;
} else {
act->action = SCP_SINK_DIR;
act->buf = dupstr(stripslashes(fname, 0));
act->name = act->buf;
act->size = uint64_make(0,0); /* duhh, it's a directory */
act->mode = 07777 & attrs.permissions;
if (scp_sftp_preserve &&
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->mtime = attrs.mtime;
act->settime = 1;
} else
act->settime = 0;
|
|
|
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
|
if (newitem->wildcard) {
act->action = SCP_SINK_RETRY;
} else {
act->action = SCP_SINK_DIR;
act->buf = dupstr(stripslashes(fname, 0));
act->name = act->buf;
act->size = uint64_make(0,0); /* duhh, it's a directory */
act->permissions = 07777 & attrs.permissions;
if (scp_sftp_preserve &&
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->mtime = attrs.mtime;
act->settime = 1;
} else
act->settime = 0;
|
| ︙ | | | ︙ | |
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
|
act->action = SCP_SINK_FILE;
act->buf = dupstr(stripslashes(fname, 0));
act->name = act->buf;
if (attrs.flags & SSH_FILEXFER_ATTR_SIZE) {
act->size = attrs.size;
} else
act->size = uint64_make(ULONG_MAX,ULONG_MAX); /* no idea */
act->mode = 07777 & attrs.permissions;
if (scp_sftp_preserve &&
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->mtime = attrs.mtime;
act->settime = 1;
} else
act->settime = 0;
|
|
|
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
|
act->action = SCP_SINK_FILE;
act->buf = dupstr(stripslashes(fname, 0));
act->name = act->buf;
if (attrs.flags & SSH_FILEXFER_ATTR_SIZE) {
act->size = attrs.size;
} else
act->size = uint64_make(ULONG_MAX,ULONG_MAX); /* no idea */
act->permissions = 07777 & attrs.permissions;
if (scp_sftp_preserve &&
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->mtime = attrs.mtime;
act->settime = 1;
} else
act->settime = 0;
|
| ︙ | | | ︙ | |
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
|
/*
* If we get here, we must have seen SCP_SINK_FILE or
* SCP_SINK_DIR.
*/
{
char sizestr[40];
if (sscanf(act->buf, "%o %s %n", &act->mode, sizestr, &i) != 2)
bump("Protocol error: Illegal file descriptor format");
act->size = uint64_from_decimal(sizestr);
act->name = act->buf + i;
return 0;
}
}
}
int scp_accept_filexfer(void)
{
if (using_sftp) {
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
sftp_register(req = fxp_open_send(scp_sftp_currentname, SSH_FXF_READ));
rreq = sftp_find_request(pktin = sftp_recv());
assert(rreq == req);
scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
if (!scp_sftp_filehandle) {
tell_user(stderr, "pscp: unable to open %s: %s",
scp_sftp_currentname, fxp_error());
|
>
|
|
>
|
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
|
/*
* If we get here, we must have seen SCP_SINK_FILE or
* SCP_SINK_DIR.
*/
{
char sizestr[40];
if (sscanf(act->buf, "%lo %s %n", &act->permissions,
sizestr, &i) != 2)
bump("Protocol error: Illegal file descriptor format");
act->size = uint64_from_decimal(sizestr);
act->name = act->buf + i;
return 0;
}
}
}
int scp_accept_filexfer(void)
{
if (using_sftp) {
struct sftp_packet *pktin;
struct sftp_request *req, *rreq;
sftp_register(req = fxp_open_send(scp_sftp_currentname, SSH_FXF_READ,
NULL));
rreq = sftp_find_request(pktin = sftp_recv());
assert(rreq == req);
scp_sftp_filehandle = fxp_open_recv(pktin, rreq);
if (!scp_sftp_filehandle) {
tell_user(stderr, "pscp: unable to open %s: %s",
scp_sftp_currentname, fxp_error());
|
| ︙ | | | ︙ | |
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
|
/*
* Execute the source part of the SCP protocol.
*/
static void source(char *src)
{
uint64 size;
unsigned long mtime, atime;
char *last;
RFile *f;
int attr;
uint64 i;
uint64 stat_bytes;
time_t stat_starttime, stat_lasttime;
|
>
|
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
|
/*
* Execute the source part of the SCP protocol.
*/
static void source(char *src)
{
uint64 size;
unsigned long mtime, atime;
long permissions;
char *last;
RFile *f;
int attr;
uint64 i;
uint64 stat_bytes;
time_t stat_starttime, stat_lasttime;
|
| ︙ | | | ︙ | |
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
|
else
last++;
if (strrchr(last, '\\') != NULL)
last = strrchr(last, '\\') + 1;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
f = open_existing_file(src, &size, &mtime, &atime);
if (f == NULL) {
run_err("%s: Cannot open file", src);
return;
}
if (preserve) {
if (scp_send_filetimes(mtime, atime))
return;
}
if (verbose) {
char sizestr[40];
uint64_decimal(size, sizestr);
tell_user(stderr, "Sending file %s, size=%s", last, sizestr);
}
if (scp_send_filename(last, size, 0644))
return;
stat_bytes = uint64_make(0,0);
stat_starttime = time(NULL);
stat_lasttime = 0;
for (i = uint64_make(0,0);
|
|
|
|
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
|
else
last++;
if (strrchr(last, '\\') != NULL)
last = strrchr(last, '\\') + 1;
if (last == src && strchr(src, ':') != NULL)
last = strchr(src, ':') + 1;
f = open_existing_file(src, &size, &mtime, &atime, &permissions);
if (f == NULL) {
run_err("%s: Cannot open file", src);
return;
}
if (preserve) {
if (scp_send_filetimes(mtime, atime))
return;
}
if (verbose) {
char sizestr[40];
uint64_decimal(size, sizestr);
tell_user(stderr, "Sending file %s, size=%s", last, sizestr);
}
if (scp_send_filename(last, size, permissions))
return;
stat_bytes = uint64_make(0,0);
stat_starttime = time(NULL);
stat_lasttime = 0;
for (i = uint64_make(0,0);
|
| ︙ | | | ︙ | |
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
|
}
}
sink(destfname, NULL);
/* can we set the timestamp for directories ? */
continue;
}
f = open_new_file(destfname);
if (f == NULL) {
run_err("%s: Cannot create file", destfname);
continue;
}
if (scp_accept_filexfer())
return;
|
|
|
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
|
}
}
sink(destfname, NULL);
/* can we set the timestamp for directories ? */
continue;
}
f = open_new_file(destfname, act.permissions);
if (f == NULL) {
run_err("%s: Cannot create file", destfname);
continue;
}
if (scp_accept_filexfer())
return;
|
| ︙ | | | ︙ | |