Diff

Differences From Artifact [da84ba00b4]:

To Artifact [f584e52a47]:


771
772
773
774
775
776
777
778

779
780
781
782
783
784
785
786
787
788
789
790
791

792
793
794
795
796
797
798
771
772
773
774
775
776
777

778
779
780
781
782
783
784
785
786
787
788
789
790

791
792
793
794
795
796
797
798







-
+












-
+







    }

    printf("Listing directory %s\n", dirname);

    sftp_register(req = fxp_opendir_send(dirname));
    rreq = sftp_find_request(pktin = sftp_recv());
    assert(rreq == req);
    dirh = fxp_opendir_recv(pktin);
    dirh = fxp_opendir_recv(pktin, rreq);

    if (dirh == NULL) {
	printf("Unable to open %s: %s\n", dirname, fxp_error());
    } else {
	nnames = namesize = 0;
	ournames = NULL;

	while (1) {

	    sftp_register(req = fxp_readdir_send(dirh));
	    rreq = sftp_find_request(pktin = sftp_recv());
	    assert(rreq == req);
	    names = fxp_readdir_recv(pktin);
	    names = fxp_readdir_recv(pktin, rreq);

	    if (names == NULL) {
		if (fxp_error_type() == SSH_FX_EOF)
		    break;
		printf("Reading directory %s: %s\n", dirname, fxp_error());
		break;
	    }
811
812
813
814
815
816
817
818

819
820
821
822
823
824
825
811
812
813
814
815
816
817

818
819
820
821
822
823
824
825







-
+








	    names->nnames = 0;	       /* prevent free_names */
	    fxp_free_names(names);
	}
	sftp_register(req = fxp_close_send(dirh));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	fxp_close_recv(pktin);
	fxp_close_recv(pktin, rreq);

	/*
	 * Now we have our filenames. Sort them by actual file
	 * name, and then output the longname parts.
	 */
	qsort(ournames, nnames, sizeof(*ournames), sftp_ls_compare);

870
871
872
873
874
875
876
877

878
879
880
881
882
883
884
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884







-
+







	    errs++;
	    return;
	}

	sftp_register(req = fxp_stat_send(target));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	ret = fxp_stat_recv(pktin, &attrs);
	ret = fxp_stat_recv(pktin, rreq, &attrs);

	if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS))
	    scp_sftp_targetisdir = 0;
	else
	    scp_sftp_targetisdir = (attrs.permissions & 0040000) != 0;

	if (shouldbedir && !scp_sftp_targetisdir) {
932
933
934
935
936
937
938
939

940
941
942
943
944
945
946
932
933
934
935
936
937
938

939
940
941
942
943
944
945
946







-
+







	    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);
	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;
	}
968
969
970
971
972
973
974
975

976
977
978
979
980
981
982
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982







-
+







	    return 1;
	}

	sftp_register(req = fxp_write_send(scp_sftp_filehandle,
					   data, scp_sftp_fileoffset, len));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	ret = fxp_write_recv(pktin);
	ret = fxp_write_recv(pktin, rreq);

	if (!ret) {
	    tell_user(stderr, "error while writing: %s\n", fxp_error());
	    errs++;
	    return 1;
	}
	scp_sftp_fileoffset = uint64_add32(scp_sftp_fileoffset, len);
1014
1015
1016
1017
1018
1019
1020
1021

1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
1028
1029

1030
1031
1032
1033
1034
1035
1036
1037







-
+








-
+







	if (scp_has_times) {
	    attrs.flags = SSH_FILEXFER_ATTR_ACMODTIME;
	    attrs.atime = scp_sftp_atime;
	    attrs.mtime = scp_sftp_mtime;
	    sftp_register(req = fxp_fsetstat_send(scp_sftp_filehandle, attrs));
	    rreq = sftp_find_request(pktin = sftp_recv());
	    assert(rreq == req);
	    ret = fxp_fsetstat_recv(pktin);
	    ret = fxp_fsetstat_recv(pktin, rreq);
	    if (!ret) {
		tell_user(stderr, "unable to set file times: %s\n", fxp_error());
		errs++;
	    }
	}
	sftp_register(req = fxp_close_send(scp_sftp_filehandle));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	fxp_close_recv(pktin);
	fxp_close_recv(pktin, rreq);
	scp_has_times = 0;
	return 0;
    } else {
	back->send(backhandle, "", 1);
	return response();
    }
}
1072
1073
1074
1075
1076
1077
1078
1079

1080
1081
1082
1083
1084
1085
1086
1087
1088
1089

1090
1091
1092
1093
1094
1095
1096
1072
1073
1074
1075
1076
1077
1078

1079
1080
1081
1082
1083
1084
1085
1086
1087
1088

1089
1090
1091
1092
1093
1094
1095
1096







-
+









-
+







	 * use it. Instead, we will stat it afterwards, and if it
	 * exists and is a directory we will assume we were either
	 * successful or it didn't matter.
	 */
	sftp_register(req = fxp_mkdir_send(fullname));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	ret = fxp_mkdir_recv(pktin);
	ret = fxp_mkdir_recv(pktin, rreq);

	if (!ret)
	    err = fxp_error();
	else
	    err = "server reported no error";

	sftp_register(req = fxp_stat_send(fullname));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	ret = fxp_stat_recv(pktin, &attrs);
	ret = fxp_stat_recv(pktin, rreq, &attrs);

	if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS) ||
	    !(attrs.permissions & 0040000)) {
	    tell_user(stderr, "unable to create directory %s: %s",
		      fullname, err);
	    errs++;
	    return 1;
1304
1305
1306
1307
1308
1309
1310
1311

1312
1313
1314
1315
1316
1317
1318
1304
1305
1306
1307
1308
1309
1310

1311
1312
1313
1314
1315
1316
1317
1318







-
+







	/*
	 * Now we have a filename. Stat it, and see if it's a file
	 * or a directory.
	 */
	sftp_register(req = fxp_stat_send(fname));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	ret = fxp_stat_recv(pktin, &attrs);
	ret = fxp_stat_recv(pktin, rreq, &attrs);

	if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) {
	    tell_user(stderr, "unable to identify %s: %s", fname,
		      ret ? "file type not supplied" : fxp_error());
	    errs++;
	    return 1;
	}
1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384

1385
1386
1387
1388
1389
1390
1391
1360
1361
1362
1363
1364
1365
1366

1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383

1384
1385
1386
1387
1388
1389
1390
1391







-
+
















-
+







	     * already in the middle of going through another such
	     * list), we must push the other (target,namelist) pair
	     * on a stack.
	     */
	    sftp_register(req = fxp_opendir_send(fname));
	    rreq = sftp_find_request(pktin = sftp_recv());
	    assert(rreq == req);
	    dirhandle = fxp_opendir_recv(pktin);
	    dirhandle = fxp_opendir_recv(pktin, rreq);

	    if (!dirhandle) {
		tell_user(stderr, "scp: unable to open directory %s: %s",
			  fname, fxp_error());
		if (must_free_fname) sfree(fname);
		errs++;
		return 1;
	    }
	    nnames = namesize = 0;
	    ournames = NULL;
	    while (1) {
		int i;

		sftp_register(req = fxp_readdir_send(dirhandle));
		rreq = sftp_find_request(pktin = sftp_recv());
		assert(rreq == req);
		names = fxp_readdir_recv(pktin);
		names = fxp_readdir_recv(pktin, rreq);

		if (names == NULL) {
		    if (fxp_error_type() == SSH_FX_EOF)
			break;
		    tell_user(stderr, "scp: reading directory %s: %s\n",
			      fname, fxp_error());
		    if (must_free_fname) sfree(fname);
1405
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
1419







-
+







		    ournames[nnames++] = names->names[i];
		names->nnames = 0;	       /* prevent free_names */
		fxp_free_names(names);
	    }
	    sftp_register(req = fxp_close_send(dirhandle));
	    rreq = sftp_find_request(pktin = sftp_recv());
	    assert(rreq == req);
	    fxp_close_recv(pktin);
	    fxp_close_recv(pktin, rreq);

	    newitem = snew(struct scp_sftp_dirstack);
	    newitem->next = scp_sftp_dirstack_head;
	    newitem->names = ournames;
	    newitem->namepos = 0;
	    newitem->namelen = nnames;
	    if (must_free_fname)
1553
1554
1555
1556
1557
1558
1559
1560

1561
1562
1563
1564
1565
1566
1567
1553
1554
1555
1556
1557
1558
1559

1560
1561
1562
1563
1564
1565
1566
1567







-
+







    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);
	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());
	    errs++;
	    return 1;
	}
1581
1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1581
1582
1583
1584
1585
1586
1587

1588
1589
1590
1591
1592
1593
1594
1595







-
+







	struct sftp_request *req, *rreq;
	int actuallen;

	sftp_register(req = fxp_read_send(scp_sftp_filehandle,
					  scp_sftp_fileoffset, len));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	actuallen = fxp_read_recv(pktin, data, len);
	actuallen = fxp_read_recv(pktin, rreq, data, len);

	if (actuallen == -1 && fxp_error_type() != SSH_FX_EOF) {
	    tell_user(stderr, "pscp: error while reading: %s", fxp_error());
	    errs++;
	    return -1;
	}
	if (actuallen < 0)
1608
1609
1610
1611
1612
1613
1614
1615

1616
1617
1618
1619
1620
1621
1622
1608
1609
1610
1611
1612
1613
1614

1615
1616
1617
1618
1619
1620
1621
1622







-
+







    if (using_sftp) {
	struct sftp_packet *pktin;
	struct sftp_request *req, *rreq;

	sftp_register(req = fxp_close_send(scp_sftp_filehandle));
	rreq = sftp_find_request(pktin = sftp_recv());
	assert(rreq == req);
	fxp_close_recv(pktin);
	fxp_close_recv(pktin, rreq);
	return 0;
    } else {
	back->send(backhandle, "", 1);
	return response();
    }
}