[BACK]Return to scp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/scp.c between version 1.242 and 1.243

version 1.242, 2022/01/08 07:36:11 version 1.243, 2022/01/17 21:39:51
Line 106 
Line 106 
 #include "misc.h"  #include "misc.h"
 #include "progressmeter.h"  #include "progressmeter.h"
 #include "utf8.h"  #include "utf8.h"
   #include "sftp.h"
   
 #include "sftp-common.h"  #include "sftp-common.h"
 #include "sftp-client.h"  #include "sftp-client.h"
Line 1241 
Line 1242 
 source_sftp(int argc, char *src, char *targ, struct sftp_conn *conn)  source_sftp(int argc, char *src, char *targ, struct sftp_conn *conn)
 {  {
         char *target = NULL, *filename = NULL, *abs_dst = NULL;          char *target = NULL, *filename = NULL, *abs_dst = NULL;
         int target_is_dir;          int src_is_dir, target_is_dir;
           Attrib a;
           struct stat st;
   
           memset(&a, '\0', sizeof(a));
           if (stat(src, &st) != 0)
                   fatal("stat local \"%s\": %s", src, strerror(errno));
           src_is_dir = S_ISDIR(st.st_mode);
         if ((filename = basename(src)) == NULL)          if ((filename = basename(src)) == NULL)
                 fatal("basename %s: %s", src, strerror(errno));                  fatal("basename \"%s\": %s", src, strerror(errno));
   
         /*          /*
          * No need to glob here - the local shell already took care of           * No need to glob here - the local shell already took care of
Line 1254 
Line 1261 
                 cleanup_exit(255);                  cleanup_exit(255);
         target_is_dir = remote_is_dir(conn, target);          target_is_dir = remote_is_dir(conn, target);
         if (targetshouldbedirectory && !target_is_dir) {          if (targetshouldbedirectory && !target_is_dir) {
                 fatal("Target is not a directory, but more files selected "                  debug("target directory \"%s\" does not exist", target);
                     "for upload");                  a.flags = SSH2_FILEXFER_ATTR_PERMISSIONS;
                   a.perm = st.st_mode | 0700; /* ensure writable */
                   if (do_mkdir(conn, target, &a, 1) != 0)
                           cleanup_exit(255); /* error already logged */
                   target_is_dir = 1;
         }          }
         if (target_is_dir)          if (target_is_dir)
                 abs_dst = path_append(target, filename);                  abs_dst = path_append(target, filename);
Line 1265 
Line 1276 
         }          }
         debug3_f("copying local %s to remote %s", src, abs_dst);          debug3_f("copying local %s to remote %s", src, abs_dst);
   
         if (local_is_dir(src) && iamrecursive) {          if (src_is_dir && iamrecursive) {
                 if (upload_dir(conn, src, abs_dst, pflag,                  if (upload_dir(conn, src, abs_dst, pflag,
                     SFTP_PROGRESS_ONLY, 0, 0, 1) != 0) {                      SFTP_PROGRESS_ONLY, 0, 0, 1) != 0) {
                         error("failed to upload directory %s to %s",                          error("failed to upload directory %s to %s",
Line 1449 
Line 1460 
         char *abs_dst = NULL;          char *abs_dst = NULL;
         glob_t g;          glob_t g;
         char *filename, *tmp = NULL;          char *filename, *tmp = NULL;
         int i, r, err = 0;          int i, r, err = 0, dst_is_dir;
           struct stat st;
   
         memset(&g, 0, sizeof(g));          memset(&g, 0, sizeof(g));
   
         /*          /*
          * Here, we need remote glob as SFTP can not depend on remote shell           * Here, we need remote glob as SFTP can not depend on remote shell
          * expansions           * expansions
          */           */
   
         if ((abs_src = prepare_remote_path(conn, src)) == NULL) {          if ((abs_src = prepare_remote_path(conn, src)) == NULL) {
                 err = -1;                  err = -1;
                 goto out;                  goto out;
Line 1472 
Line 1484 
                 goto out;                  goto out;
         }          }
   
         if (g.gl_matchc > 1 && !local_is_dir(dst)) {          if ((r = stat(dst, &st)) != 0)
                 error("Multiple files match pattern, but destination "                  debug2_f("stat local \"%s\": %s", dst, strerror(errno));
                     "\"%s\" is not a directory", dst);          dst_is_dir = r == 0 && S_ISDIR(st.st_mode);
                 err = -1;  
                 goto out;          if (g.gl_matchc > 1 && !dst_is_dir) {
                   if (r == 0) {
                           error("Multiple files match pattern, but destination "
                               "\"%s\" is not a directory", dst);
                           err = -1;
                           goto out;
                   }
                   debug2_f("creating destination \"%s\"", dst);
                   if (mkdir(dst, 0777) != 0) {
                           error("local mkdir \"%s\": %s", dst, strerror(errno));
                           err = -1;
                           goto out;
                   }
                   dst_is_dir = 1;
         }          }
   
         for (i = 0; g.gl_pathv[i] && !interrupted; i++) {          for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
Line 1487 
Line 1512 
                         goto out;                          goto out;
                 }                  }
   
                 if (local_is_dir(dst))                  if (dst_is_dir)
                         abs_dst = path_append(dst, filename);                          abs_dst = path_append(dst, filename);
                 else                  else
                         abs_dst = xstrdup(dst);                          abs_dst = xstrdup(dst);

Legend:
Removed from v.1.242  
changed lines
  Added in v.1.243