1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Add the -ls option to execute `ls -la' on a directory instead of

trying to copy anything. Likely to be useful for GUI front ends.

[originally from svn r435]
This commit is contained in:
Simon Tatham 2000-04-03 19:54:31 +00:00
parent f60f25a35a
commit 0ac9df8251

93
scp.c
View File

@ -178,7 +178,7 @@ static void print_stats(char *name, unsigned long size, unsigned long done,
/* /*
* Find a colon in str and return a pointer to the colon. * 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) static char * colon(char *str)
{ {
@ -592,7 +592,7 @@ static void toremote(int argc, char *argv[])
targ = argv[argc-1]; targ = argv[argc-1];
/* Seperate host from filename */ /* Separate host from filename */
host = targ; host = targ;
targ = colon(targ); targ = colon(targ);
if (targ == NULL) if (targ == NULL)
@ -602,7 +602,7 @@ static void toremote(int argc, char *argv[])
targ = "."; targ = ".";
/* Substitute "." for emtpy target */ /* Substitute "." for emtpy target */
/* Seperate host and username */ /* Separate host and username */
user = host; user = host;
host = strrchr(host, '@'); host = strrchr(host, '@');
if (host == NULL) { if (host == NULL) {
@ -694,7 +694,7 @@ static void tolocal(int argc, char *argv[])
src = argv[0]; src = argv[0];
targ = argv[1]; targ = argv[1];
/* Seperate host from filename */ /* Separate host from filename */
host = src; host = src;
src = colon(src); src = colon(src);
if (src == NULL) if (src == NULL)
@ -704,7 +704,7 @@ static void tolocal(int argc, char *argv[])
src = "."; src = ".";
/* Substitute "." for empty filename */ /* Substitute "." for empty filename */
/* Seperate username and hostname */ /* Separate username and hostname */
user = host; user = host;
host = strrchr(host, '@'); host = strrchr(host, '@');
if (host == NULL) { if (host == NULL) {
@ -729,6 +729,59 @@ static void tolocal(int argc, char *argv[])
sink(targ); 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. * Initialize the Win$ock driver.
*/ */
@ -770,6 +823,7 @@ static void usage(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i; int i;
int list = 0;
init_winsock(); init_winsock();
@ -791,6 +845,8 @@ int main(int argc, char *argv[])
portnumber = atoi(argv[++i]); portnumber = atoi(argv[++i]);
else if (strcmp(argv[i], "-pw") == 0 && i+1 < argc) else if (strcmp(argv[i], "-pw") == 0 && i+1 < argc)
password = argv[++i]; password = argv[++i];
else if (strcmp(argv[i], "-ls") == 0)
list = 1;
else if (strcmp(argv[i], "--") == 0) else if (strcmp(argv[i], "--") == 0)
{ i++; break; } { i++; break; }
else else
@ -799,24 +855,29 @@ int main(int argc, char *argv[])
argc -= i; argc -= i;
argv += i; argv += i;
if (argc < 2) if (list) {
usage(); if (argc != 1)
if (argc > 2) usage();
targetshouldbedirectory = 1; get_dir_list(argc, argv);
if (colon(argv[argc-1]) != NULL) } else {
toremote(argc, argv);
else if (argc < 2)
tolocal(argc, argv); usage();
if (argc > 2)
targetshouldbedirectory = 1;
if (colon(argv[argc-1]) != NULL)
toremote(argc, argv);
else
tolocal(argc, argv);
}
if (connection_open) { if (connection_open) {
char ch; char ch;
ssh_send_eof(); ssh_send_eof();
ssh_recv(&ch, 1); ssh_recv(&ch, 1);
} }
#ifdef MSCRYPTOAPI
crypto_wrapup();
#endif
WSACleanup(); WSACleanup();
random_save_seed(); random_save_seed();