| ︙ | | |
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
-
+
|
if (done == size)
printf("\n");
}
/*
* Find a colon in str and return a pointer to the colon.
* This is used to seperate hostname from filename.
* This is used to separate hostname from filename.
*/
static char * colon(char *str)
{
/* We ignore a leading colon, since the hostname cannot be
empty. We also ignore a colon as second character because
of filenames like f:myfile.txt. */
if (str[0] == '\0' ||
|
| ︙ | | |
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
-
+
-
+
|
{
char *src, *targ, *host, *user;
char *cmd;
int i;
targ = argv[argc-1];
/* Seperate host from filename */
/* Separate host from filename */
host = targ;
targ = colon(targ);
if (targ == NULL)
bump("targ == NULL in toremote()");
*targ++ = '\0';
if (*targ == '\0')
targ = ".";
/* Substitute "." for emtpy target */
/* Seperate host and username */
/* Separate host and username */
user = host;
host = strrchr(host, '@');
if (host == NULL) {
host = user;
user = NULL;
} else {
*host++ = '\0';
|
| ︙ | | |
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
-
+
-
+
|
if (argc != 2)
bump("More than one remote source not supported");
src = argv[0];
targ = argv[1];
/* Seperate host from filename */
/* Separate host from filename */
host = src;
src = colon(src);
if (src == NULL)
bump("Local to local copy not supported");
*src++ = '\0';
if (*src == '\0')
src = ".";
/* Substitute "." for empty filename */
/* Seperate username and hostname */
/* Separate username and hostname */
user = host;
host = strrchr(host, '@');
if (host == NULL) {
host = user;
user = NULL;
} else {
*host++ = '\0';
|
| ︙ | | |
724
725
726
727
728
729
730
731
732
733
734
735
736
737
|
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
targetshouldbedirectory ? " -d" : "",
src);
do_cmd(host, user, cmd);
sfree(cmd);
sink(targ);
}
/*
* We will issue a list command to get a remote directory.
*/
static void get_dir_list(int argc, char *argv[])
{
char *src, *host, *user;
char *cmd, *p, *q;
char c;
src = argv[0];
/* Separate host from filename */
host = src;
src = colon(src);
if (src == NULL)
bump("Local to local copy not supported");
*src++ = '\0';
if (*src == '\0')
src = ".";
/* Substitute "." for empty filename */
/* Separate username and hostname */
user = host;
host = strrchr(host, '@');
if (host == NULL) {
host = user;
user = NULL;
} else {
*host++ = '\0';
if (*user == '\0')
user = NULL;
}
cmd = smalloc(4*strlen(src) + 100);
strcpy(cmd, "ls -la '");
p = cmd + strlen(cmd);
for (q = src; *q; q++) {
if (*q == '\'') {
*p++ = '\''; *p++ = '\\'; *p++ = '\''; *p++ = '\'';
} else {
*p++ = *q;
}
}
*p++ = '\'';
*p = '\0';
do_cmd(host, user, cmd);
sfree(cmd);
while (ssh_recv(&c, 1) > 0)
fputc(c, stdout); /* thank heavens for buffered I/O */
}
/*
* Initialize the Win$ock driver.
*/
static void init_winsock(void)
{
WORD winsock_ver;
|
| ︙ | | |
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
|
+
|
/*
* Main program (no, really?)
*/
int main(int argc, char *argv[])
{
int i;
int list = 0;
init_winsock();
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-')
break;
if (strcmp(argv[i], "-v") == 0)
|
| ︙ | | |
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
|
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
882
883
884
885
886
887
|
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
+
+
-
-
-
|
else if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "-?") == 0)
usage();
else if (strcmp(argv[i], "-P") == 0 && i+1 < argc)
portnumber = atoi(argv[++i]);
else if (strcmp(argv[i], "-pw") == 0 && i+1 < argc)
password = argv[++i];
else if (strcmp(argv[i], "-ls") == 0)
list = 1;
else if (strcmp(argv[i], "--") == 0)
{ i++; break; }
else
usage();
}
argc -= i;
argv += i;
if (list) {
if (argc != 1)
usage();
get_dir_list(argc, argv);
} else {
if (argc < 2)
usage();
if (argc > 2)
targetshouldbedirectory = 1;
if (argc < 2)
usage();
if (argc > 2)
targetshouldbedirectory = 1;
if (colon(argv[argc-1]) != NULL)
toremote(argc, argv);
else
tolocal(argc, argv);
if (colon(argv[argc-1]) != NULL)
toremote(argc, argv);
else
tolocal(argc, argv);
}
if (connection_open) {
char ch;
ssh_send_eof();
ssh_recv(&ch, 1);
}
#ifdef MSCRYPTOAPI
crypto_wrapup();
#endif
WSACleanup();
random_save_seed();
return (errs == 0 ? 0 : 1);
}
/* end */
|