]> andersk Git - openssh.git/blobdiff - sftp.c
- stevesk@cvs.openbsd.org 2009/04/13 19:07:44
[openssh.git] / sftp.c
diff --git a/sftp.c b/sftp.c
index ffc35cb83c75273e742527c68be20a4708c24ef7..66bd111b122c47ad5ca7380cda5261a424f675e0 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.100 2008/04/18 12:32:11 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.107 2009/02/02 11:15:14 dtucker Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -25,7 +25,9 @@
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
+#ifdef HAVE_SYS_STATVFS_H
 #include <sys/statvfs.h>
+#endif
 
 #include <ctype.h>
 #include <errno.h>
@@ -73,7 +75,7 @@ int batchmode = 0;
 size_t copy_buffer_len = 32768;
 
 /* Number of concurrent outstanding requests */
-size_t num_requests = 16;
+size_t num_requests = 64;
 
 /* PID of ssh transport process */
 static pid_t sshpid = -1;
@@ -205,36 +207,37 @@ cmd_interrupt(int signo)
 static void
 help(void)
 {
-       printf("Available commands:\n");
-       printf("cd path                       Change remote directory to 'path'\n");
-       printf("lcd path                      Change local directory to 'path'\n");
-       printf("chgrp grp path                Change group of file 'path' to 'grp'\n");
-       printf("chmod mode path               Change permissions of file 'path' to 'mode'\n");
-       printf("chown own path                Change owner of file 'path' to 'own'\n");
-       printf("df [path]                     Display statistics for current directory or\n");
-       printf("                              filesystem containing 'path'\n");
-       printf("help                          Display this help text\n");
-       printf("get remote-path [local-path]  Download file\n");
-       printf("lls [ls-options [path]]       Display local directory listing\n");
-       printf("ln oldpath newpath            Symlink remote file\n");
-       printf("lmkdir path                   Create local directory\n");
-       printf("lpwd                          Print local working directory\n");
-       printf("ls [path]                     Display remote directory listing\n");
-       printf("lumask umask                  Set local umask to 'umask'\n");
-       printf("mkdir path                    Create remote directory\n");
-       printf("progress                      Toggle display of progress meter\n");
-       printf("put local-path [remote-path]  Upload file\n");
-       printf("pwd                           Display remote working directory\n");
-       printf("exit                          Quit sftp\n");
-       printf("quit                          Quit sftp\n");
-       printf("rename oldpath newpath        Rename remote file\n");
-       printf("rmdir path                    Remove remote directory\n");
-       printf("rm path                       Delete remote file\n");
-       printf("symlink oldpath newpath       Symlink remote file\n");
-       printf("version                       Show SFTP version\n");
-       printf("!command                      Execute 'command' in local shell\n");
-       printf("!                             Escape to local shell\n");
-       printf("?                             Synonym for help\n");
+       printf("Available commands:\n"
+           "bye                                Quit sftp\n"
+           "cd path                            Change remote directory to 'path'\n"
+           "chgrp grp path                     Change group of file 'path' to 'grp'\n"
+           "chmod mode path                    Change permissions of file 'path' to 'mode'\n"
+           "chown own path                     Change owner of file 'path' to 'own'\n"
+           "df [-hi] [path]                    Display statistics for current directory or\n"
+           "                                   filesystem containing 'path'\n"
+           "exit                               Quit sftp\n"
+           "get [-P] remote-path [local-path]  Download file\n"
+           "help                               Display this help text\n"
+           "lcd path                           Change local directory to 'path'\n"
+           "lls [ls-options [path]]            Display local directory listing\n"
+           "lmkdir path                        Create local directory\n"
+           "ln oldpath newpath                 Symlink remote file\n"
+           "lpwd                               Print local working directory\n"
+           "ls [-1aflnrSt] [path]              Display remote directory listing\n"
+           "lumask umask                       Set local umask to 'umask'\n"
+           "mkdir path                         Create remote directory\n"
+           "progress                           Toggle display of progress meter\n"
+           "put [-P] local-path [remote-path]  Upload file\n"
+           "pwd                                Display remote working directory\n"
+           "quit                               Quit sftp\n"
+           "rename oldpath newpath             Rename remote file\n"
+           "rm path                            Delete remote file\n"
+           "rmdir path                         Remove remote directory\n"
+           "symlink oldpath newpath            Symlink remote file\n"
+           "version                            Show SFTP version\n"
+           "!command                           Execute 'command' in local shell\n"
+           "!                                  Escape to local shell\n"
+           "?                                  Synonym for help\n");
 }
 
 static void
@@ -362,7 +365,7 @@ infer_path(const char *p, char **ifp)
 static int
 parse_getput_flags(const char *cmd, char **argv, int argc, int *pflag)
 {
-       extern int optind, optreset, opterr;
+       extern int opterr, optind, optopt, optreset;
        int ch;
 
        optind = optreset = 1;
@@ -376,7 +379,7 @@ parse_getput_flags(const char *cmd, char **argv, int argc, int *pflag)
                        *pflag = 1;
                        break;
                default:
-                       error("%s: Invalid flag -%c", cmd, ch);
+                       error("%s: Invalid flag -%c", cmd, optopt);
                        return -1;
                }
        }
@@ -387,7 +390,7 @@ parse_getput_flags(const char *cmd, char **argv, int argc, int *pflag)
 static int
 parse_ls_flags(char **argv, int argc, int *lflag)
 {
-       extern int optind, optreset, opterr;
+       extern int opterr, optind, optopt, optreset;
        int ch;
 
        optind = optreset = 1;
@@ -426,7 +429,7 @@ parse_ls_flags(char **argv, int argc, int *lflag)
                        *lflag |= LS_TIME_SORT;
                        break;
                default:
-                       error("ls: Invalid flag -%c", ch);
+                       error("ls: Invalid flag -%c", optopt);
                        return -1;
                }
        }
@@ -437,7 +440,7 @@ parse_ls_flags(char **argv, int argc, int *lflag)
 static int
 parse_df_flags(const char *cmd, char **argv, int argc, int *hflag, int *iflag)
 {
-       extern int optind, optreset, opterr;
+       extern int opterr, optind, optopt, optreset;
        int ch;
 
        optind = optreset = 1;
@@ -453,7 +456,7 @@ parse_df_flags(const char *cmd, char **argv, int argc, int *hflag, int *iflag)
                        *iflag = 1;
                        break;
                default:
-                       error("%s: Invalid flag -%c", cmd, ch);
+                       error("%s: Invalid flag -%c", cmd, optopt);
                        return -1;
                }
        }
@@ -840,7 +843,7 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
 static int
 do_df(struct sftp_conn *conn, char *path, int hflag, int iflag)
 {
-       struct statvfs st;
+       struct sftp_statvfs st;
        char s_used[FMT_SCALED_STRSIZE];
        char s_avail[FMT_SCALED_STRSIZE];
        char s_root[FMT_SCALED_STRSIZE];
@@ -1232,8 +1235,8 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
     int err_abort)
 {
        char *path1, *path2, *tmp;
-       int pflag, lflag, iflag, hflag, cmdnum, i;
-       unsigned long n_arg;
+       int pflag = 0, lflag = 0, iflag = 0, hflag = 0, cmdnum, i;
+       unsigned long n_arg = 0;
        Attrib a, *aa;
        char path_buf[MAXPATHLEN];
        int err = 0;
@@ -1384,17 +1387,19 @@ parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd,
                remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
                for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                        if (!(aa = do_stat(conn, g.gl_pathv[i], 0))) {
-                               if (err != 0 && err_abort)
+                               if (err_abort) {
+                                       err = -1;
                                        break;
-                               else
+                               else
                                        continue;
                        }
                        if (!(aa->flags & SSH2_FILEXFER_ATTR_UIDGID)) {
                                error("Can't get current ownership of "
                                    "remote file \"%s\"", g.gl_pathv[i]);
-                               if (err != 0 && err_abort)
+                               if (err_abort) {
+                                       err = -1;
                                        break;
-                               else
+                               else
                                        continue;
                        }
                        aa->flags &= SSH2_FILEXFER_ATTR_UIDGID;
@@ -1666,8 +1671,8 @@ usage(void)
            "usage: %s [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]\n"
            "            [-o ssh_option] [-P sftp_server_path] [-R num_requests]\n"
            "            [-S program] [-s subsystem | sftp_server] host\n"
-           "       %s [[user@]host[:file [file]]]\n"
-           "       %s [[user@]host[:dir[/]]]\n"
+           "       %s [user@]host[:file ...]\n"
+           "       %s [user@]host[:dir[/]]\n"
            "       %s -b batchfile [user@]host\n", __progname, __progname, __progname, __progname);
        exit(1);
 }
This page took 0.046252 seconds and 4 git commands to generate.