Re: ftp mput recursiv upload diff for testing

2012-10-12 Thread Christiano F. Haesbaert
ok haesbaert, sorry for the slacking :=).

On Sat, Aug 11, 2012 at 05:48:13PM +0200, Alexander Bluhm wrote:
 On Mon, Jul 30, 2012 at 10:30:47AM +0200, Jan Klemkow wrote:
  Hopefully the final version.
 
 Yes, I think this is OK now.  If anybody else could have a look at
 it, I will commit it.
 
 bluhm
 
  
  Index: cmds.c
  ===
  RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
  retrieving revision 1.70
  diff -u -p -r1.70 cmds.c
  --- cmds.c  5 May 2009 19:35:30 -   1.70
  +++ cmds.c  30 Jul 2012 07:58:16 -
  @@ -231,15 +231,32 @@ mput(int argc, char *argv[])
  extern int optind, optreset;
  int ch, i, restartit = 0;
  sig_t oldintr;
  -   char *cmd, *tp;
  +   char *cmd, *tp, *xargv[] = { argv[0], NULL, NULL };
  +   const char *errstr;
  +   static int depth = 0, max_depth = 0;
   
  optind = optreset = 1;
   
  -   while ((ch = getopt(argc, argv, c)) != -1) {
  +   if (depth)
  +   depth++;
  +
  +   while ((ch = getopt(argc, argv, cd:r)) != -1) {
  switch(ch) {
  case 'c':
  restartit = 1;
  break;
  +   case 'd':
  +   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
  +   if (errstr != NULL) {
  +   fprintf(ttyout, bad depth value, %s: %s\n,
  +   errstr, optarg);
  +   code = -1;
  +   return;
  +   }
  +   break;
  +   case 'r':
  +   depth = 1;
  +   break;
  default:
  goto usage;
  }
  @@ -247,7 +264,8 @@ mput(int argc, char *argv[])
   
  if (argc - optind  1  !another(argc, argv, local-files)) {
   usage:
  -   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
  +   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
  +   argv[0]);
  code = -1;
  return;
  }
  @@ -318,11 +336,13 @@ usage:
  mflag = 0;
  return;
  }
  +
  for (i = 1; i  argc; i++) {
  char **cpp;
  glob_t gl;
  int flags;
   
  +   /* Copy files without word expansion */
  if (!doglob) {
  if (mflag  confirm(argv[0], argv[i])) {
  tp = (ntflag) ? dotrans(argv[i]) : argv[i];
  @@ -348,6 +368,7 @@ usage:
  continue;
  }
   
  +   /* expanding file names */
  memset(gl, 0, sizeof(gl));
  flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
  if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
  @@ -355,33 +376,89 @@ usage:
  globfree(gl);
  continue;
  }
  +
  +   /* traverse all expanded file names */
  for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
  -   if (mflag  confirm(argv[0], *cpp)) {
  -   tp = (ntflag) ? dotrans(*cpp) : *cpp;
  -   tp = (mapflag) ? domap(tp) : tp;
  -   if (restartit == 1) {
  -   off_t ret;
  +   struct stat filestat;
   
  -   if (curtype != type)
  -   changetype(type, 0);
  -   ret = remotesize(tp, 0);
  -   restart_point = (ret  0) ? 0 : ret;
  -   }
  -   cmd = restartit ? APPE : ((sunique) ?
  -   STOU : STOR);
  -   sendrequest(cmd, *cpp, tp,
  -   *cpp != tp || !interactive);
  -   restart_point = 0;
  -   if (!mflag  fromatty) {
  -   if (confirm(argv[0], NULL))
  -   mflag = 1;
  +   if (!mflag)
  +   continue;
  +   if (stat(*cpp, filestat) != 0) {
  +   warn(local: %s, *cpp);
  +   continue;
  +   }
  +   if (S_ISDIR(filestat.st_mode)  depth == max_depth)
  +   continue;
  +   if (!confirm(argv[0], *cpp))
  +   continue;
  +
  +   /*
  +* If file is a directory then create a new one
  +* at the remote machine.
  +*/
  +   if (S_ISDIR(filestat.st_mode)) {
  +   xargv[1] = *cpp;
  +   makedir(2, xargv);
  +   cd(2, xargv);
  +   if 

Re: ftp mput recursiv upload diff for testing

2012-07-30 Thread Jan Klemkow
Hopefully the final version.

Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  30 Jul 2012 07:58:16 -
@@ -231,15 +231,32 @@ mput(int argc, char *argv[])
extern int optind, optreset;
int ch, i, restartit = 0;
sig_t oldintr;
-   char *cmd, *tp;
+   char *cmd, *tp, *xargv[] = { argv[0], NULL, NULL };
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
 
optind = optreset = 1;
 
-   while ((ch = getopt(argc, argv, c)) != -1) {
+   if (depth)
+   depth++;
+
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s\n,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +264,8 @@ mput(int argc, char *argv[])
 
if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +336,13 @@ usage:
mflag = 0;
return;
}
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;
 
+   /* Copy files without word expansion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +368,7 @@ usage:
continue;
}
 
+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,33 +376,89 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
-   if (mflag  confirm(argv[0], *cpp)) {
-   tp = (ntflag) ? dotrans(*cpp) : *cpp;
-   tp = (mapflag) ? domap(tp) : tp;
-   if (restartit == 1) {
-   off_t ret;
+   struct stat filestat;
 
-   if (curtype != type)
-   changetype(type, 0);
-   ret = remotesize(tp, 0);
-   restart_point = (ret  0) ? 0 : ret;
-   }
-   cmd = restartit ? APPE : ((sunique) ?
-   STOU : STOR);
-   sendrequest(cmd, *cpp, tp,
-   *cpp != tp || !interactive);
-   restart_point = 0;
-   if (!mflag  fromatty) {
-   if (confirm(argv[0], NULL))
-   mflag = 1;
+   if (!mflag)
+   continue;
+   if (stat(*cpp, filestat) != 0) {
+   warn(local: %s, *cpp);
+   continue;
+   }
+   if (S_ISDIR(filestat.st_mode)  depth == max_depth)
+   continue;
+   if (!confirm(argv[0], *cpp))
+   continue;
+
+   /*
+* If file is a directory then create a new one
+* at the remote machine.
+*/
+   if (S_ISDIR(filestat.st_mode)) {
+   xargv[1] = *cpp;
+   makedir(2, xargv);
+   cd(2, xargv);
+   if (dirchange != 1) {
+   warnx(remote: %s, *cpp);
+ 

Re: ftp mput recursiv upload diff for testing

2012-07-28 Thread Jan Klemkow
I fixed a few things from the mails bevor...

Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  28 Jul 2012 19:48:56 -
@@ -231,15 +231,32 @@ mput(int argc, char *argv[])
extern int optind, optreset;
int ch, i, restartit = 0;
sig_t oldintr;
-   char *cmd, *tp;
+   char *cmd, *tp, *xargv[] = { argv[0], NULL, NULL };
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
 
optind = optreset = 1;
 
-   while ((ch = getopt(argc, argv, c)) != -1) {
+   if (depth)
+   depth++;
+
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s\n,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +264,8 @@ mput(int argc, char *argv[])
 
if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +336,13 @@ usage:
mflag = 0;
return;
}
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;
 
+   /* Copy files without word expansion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +368,7 @@ usage:
continue;
}
 
+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,33 +376,88 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
-   if (mflag  confirm(argv[0], *cpp)) {
-   tp = (ntflag) ? dotrans(*cpp) : *cpp;
-   tp = (mapflag) ? domap(tp) : tp;
-   if (restartit == 1) {
-   off_t ret;
+   struct stat filestat;
 
-   if (curtype != type)
-   changetype(type, 0);
-   ret = remotesize(tp, 0);
-   restart_point = (ret  0) ? 0 : ret;
-   }
-   cmd = restartit ? APPE : ((sunique) ?
-   STOU : STOR);
-   sendrequest(cmd, *cpp, tp,
-   *cpp != tp || !interactive);
-   restart_point = 0;
-   if (!mflag  fromatty) {
-   if (confirm(argv[0], NULL))
-   mflag = 1;
+   if (!mflag)
+   continue;
+   if (stat(*cpp, filestat) != 0) {
+   warn(NULL);
+   continue;
+   }
+   if (S_ISDIR(filestat.st_mode)  depth == max_depth)
+   continue;
+   if (!confirm(argv[0], *cpp))
+   continue;
+
+   /*
+* If file is a directory then create a new one
+* at the remote machine.
+*/
+   if (S_ISDIR(filestat.st_mode)) {
+   xargv[1] = *cpp;
+   makedir(2, xargv);
+   cd(2, xargv);
+   if (dirchange != 1) {
+   warnx(remote: %s, *cpp);
+

Re: ftp mput recursiv upload diff for testing

2012-07-28 Thread Alexander Bluhm
On Sat, Jul 28, 2012 at 10:02:05PM +0200, Jan Klemkow wrote:
 + if (stat(*cpp, filestat) != 0) {
 + warn(NULL);
warn(local: %s, *cpp);
So the user can see which file causes trouble.
 + continue;
 + }

 + if (chdir(..) != 0) {
 + mflag = 0;
warn(local: %s, *cpp);
You have a warning in all other cases, put one here too.
 + goto out;
 + }

bluhm



Re: ftp mput recursiv upload diff for testing

2012-07-23 Thread Jan Klemkow
Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  23 Jul 2012 18:49:30 -
@@ -231,15 +231,32 @@ mput(int argc, char *argv[])
extern int optind, optreset;
int ch, i, restartit = 0;
sig_t oldintr;
-   char *cmd, *tp;
+   char *cmd, *tp, *xargv[] = { argv[0], NULL, NULL };
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
 
optind = optreset = 1;
 
-   while ((ch = getopt(argc, argv, c)) != -1) {
+   if (depth)
+   depth++;
+
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s\n,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +264,8 @@ mput(int argc, char *argv[])
 
if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +336,13 @@ usage:
mflag = 0;
return;
}
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;
 
+   /* Copy files without word expansion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +368,7 @@ usage:
continue;
}
 
+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,33 +376,83 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
-   if (mflag  confirm(argv[0], *cpp)) {
-   tp = (ntflag) ? dotrans(*cpp) : *cpp;
-   tp = (mapflag) ? domap(tp) : tp;
-   if (restartit == 1) {
-   off_t ret;
+   struct stat filestat;
 
-   if (curtype != type)
-   changetype(type, 0);
-   ret = remotesize(tp, 0);
-   restart_point = (ret  0) ? 0 : ret;
-   }
-   cmd = restartit ? APPE : ((sunique) ?
-   STOU : STOR);
-   sendrequest(cmd, *cpp, tp,
-   *cpp != tp || !interactive);
-   restart_point = 0;
-   if (!mflag  fromatty) {
-   if (confirm(argv[0], NULL))
-   mflag = 1;
+   if (!mflag)
+   continue;
+   if (!confirm(argv[0], *cpp))
+   continue;
+
+   /*
+* If file is a directory then create a new one
+* at the remote machine.
+*/
+   if (stat(*cpp, filestat) != 0) {
+   perror(NULL);
+   continue;
+   }
+   if (S_ISDIR(filestat.st_mode)  !(depth == max_depth)){
+   xargv[1] = *cpp;
+   makedir(2, xargv);
+   cd(2, xargv);
+   if (dirchange != 1) {
+   warn(remote: %s, *cpp);
+   continue;
+   }
+
+   if (chdir(*cpp) != 0) {
+  

Re: ftp mput recursiv upload diff for testing

2012-07-17 Thread Alexander Bluhm
On Sun, Jul 15, 2012 at 02:54:31PM +0200, Jan Klemkow wrote:
 + if (!mflag)
 + continue;
 + if (depth == max_depth)
 + continue;

This breaks the non recursive case.  There depth and max_depth are
always 0.  Do if (S_ISDIR(filestat.st_mode)  depth == max_depth)
as I have already suggested.

 + if (!confirm(argv[0], *cpp))
 + continue;
 +
 + /*
 +  * If file is a directory then create a new one
 +  * at the remote machine.
 +  */
 + stat(*cpp, filestat);

Please do the error check.

 + if (S_ISDIR(filestat.st_mode)) {
 + xargv[1] = *cpp;
 + makedir(2, xargv);
 + cd(2, xargv);
 + if (dirchange != 1) {
 + warn(remote: %s, *cpp);
 + mflag = 0;

mget does not set mflag = 0 here.  If we cannot create a remote
directory, just print the error message and skip this file.
Don't stop recursion.

 + continue;
 + }
 +
 + if (chdir(*cpp) != 0) {
 + warn(local: %s, *cpp);

mget does not warn here.  This should not happen anyway.  But perhaps
it would be better to add a warning in mget than to remove it here.

 + goto out;
 + }
 +
 + /* Copy the whole directory recursively. */
 + xargv[1] = *;
 + mput(2, xargv);
 +
 + if (chdir(..) != 0) {
 + warn(local: %s, *cpp);

mget does not warn here.  This should not happen anyway.

 + mflag = 0;

mget has a goto out here.  Of course that does not change anything.
But it shows that the correct error handling has been considered.

 + }
 + out:
 + xargv[1] = ..;
 + cd(2, xargv);
 + if (dirchange != 1) {
 + warn(remote: %s, *cpp);
 + mflag = 0;
   }
 + continue;
 + }

bluhm



Re: ftp mput recursiv upload diff for testing

2012-07-13 Thread Alexander Bluhm
On Fri, Jul 13, 2012 at 03:23:26AM +0200, Jan Klemkow wrote:

 +   char *cmd, *tp, *xargv[] = {argv[0], NULL, NULL};
Put spaces inside {}:  { argv[0], NULL, NULL }

 It took me a while to figure out what that code does, so I think the
 comments are usefull for everybody who tries to read it.

 + /*
 +  * Copy the hole directory recursivly.
 +  */

It is spelled recursively.

 The file type information comes from this special remglob2() function.
 There is no equivalent thing in the context of mput().  So I check the
 local file type with stat(2) and S_ISDIR().

   if (mflag  confirm(argv[0], *cpp)) {
 +
 + /*
 +  * If file is a directory then create a new one
 +  * at the remote machine.
 +  */
 + stat(*cpp, filestat);
 +
 + if (S_ISDIR(filestat.st_mode)) {
 +
 + if (depth == max_depth)
 + continue;

With maximum depth mput() may prompt for directories it will skip
later.  So move the check before the prompt like in mget():

if (!mflag)
continue;
if (stat(*cpp, filestat) == -1)
continue;
if (S_ISDIR(filestat.st_mode)  depth == max_depth)
continue;
if (!confirm(argv[0], *cpp))
continue;
if (S_ISDIR(filestat.st_mode)) {

 The makedir() function has no return value, so it is not posible at the
 moment to detect an error inside that function.

 + xargv[1] = *cpp;
 + makedir(2, xargv);
 +
 + /*
 +  * Copy the hole directory recursivly.
 +  */
 + if (chdir(*cpp) != 0) {
 + warn(local: %s, *cpp);
 + continue;
 + }
 +
 + xargv[1] = *cpp;
 + cd(2, xargv);
 + if (dirchange != 1) {
 + mflag = 0;
 + goto out;
 + }

To verify that makedir() succeeded, do a cd() immediately after it.
Reorder the function calls like this:

/*
 * Copy the hole directory recursivly.
 */
if (chdir(*cpp) != 0) {
warn(local: %s, *cpp);
continue;
}
   
xargv[1] = *cpp;
makedir(2, xargv);
cd(2, xargv);
if (dirchange != 1) {
mflag = 0;
goto out;
}

bluhm



Re: ftp mput recursiv upload diff for testing

2012-07-13 Thread Otto Moerbeek
On Fri, Jul 13, 2012 at 06:58:48PM +0200, Alexander Bluhm wrote:

 On Fri, Jul 13, 2012 at 03:23:26AM +0200, Jan Klemkow wrote:
 
  +   char *cmd, *tp, *xargv[] = {argv[0], NULL, NULL};
 Put spaces inside {}:  { argv[0], NULL, NULL }
 
  It took me a while to figure out what that code does, so I think the
  comments are usefull for everybody who tries to read it.
 
  +   /*
  +* Copy the hole directory recursivly.
  +*/
 
 It is spelled recursively.

and whole...

-Otto



Re: ftp mput recursiv upload diff for testing

2012-07-12 Thread Alexander Bluhm
Comments inline:

On Mon, Jul 09, 2012 at 02:04:27PM +0200, Jan Klemkow wrote:
 Index: cmds.c
 ===
 RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
 retrieving revision 1.70
 diff -u -p -r1.70 cmds.c
 --- cmds.c5 May 2009 19:35:30 -   1.70
 +++ cmds.c9 Jul 2012 11:56:54 -
 @@ -229,17 +229,30 @@ void
  mput(int argc, char *argv[])
  {
   extern int optind, optreset;
 - int ch, i, restartit = 0;
 + int ch, i, restartit = 0, recursiv = 0;
s/recursiv/recursive/
And this variable is not used.

   sig_t oldintr;
   char *cmd, *tp;
 -
 + const char *errstr;
 + static int depth = 0, max_depth = 0;
Put an emtpy line after the declarations

   optind = optreset = 1;
  
 - while ((ch = getopt(argc, argv, c)) != -1) {
 + while ((ch = getopt(argc, argv, cd:r)) != -1) {
   switch(ch) {
   case 'c':
   restartit = 1;
   break;
 + case 'd':
 + max_depth = strtonum(optarg, 0, INT_MAX, errstr);
 + if (errstr != NULL) {
 + fprintf(ttyout, bad depth value, %s: %s,
\n missing

 + errstr, optarg);
 + code = -1;
 + return;
 + }
 + break;
 + case 'r':
 + depth = 1;
 + break;
   default:
   goto usage;
   }
 @@ -247,7 +260,8 @@ mput(int argc, char *argv[])
  
   if (argc - optind  1  !another(argc, argv, local-files)) {
  usage:
 - fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
 + fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
 + argv[0]);
   code = -1;
   return;
   }
 @@ -318,11 +332,16 @@ usage:
   mflag = 0;
   return;
   }
 +
 + if (depth)
 + depth++;
 +
Should this be before getopt like in mget?
After -r depth = 1 case, depth gets incremented to 2 here and is
not reset correctly to 0 after all.  Try mput -r and mput, the
second one will still be recursive.

   for (i = 1; i  argc; i++) {
   char **cpp;
   glob_t gl;
   int flags;
  
 + /* Copy files without word expantion */
s/expantion/expansion/
Needless comments, unecessary diff.

   if (!doglob) {
   if (mflag  confirm(argv[0], argv[i])) {
   tp = (ntflag) ? dotrans(argv[i]) : argv[i];
 @@ -348,6 +367,7 @@ usage:
   continue;
   }
  
 + /* expanding file names */
Needless comments, unecessary diff.

   memset(gl, 0, sizeof(gl));
   flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
   if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
 @@ -355,8 +375,58 @@ usage:
   globfree(gl);
   continue;
   }
 +
 + /* traverse all expanded file names */
Needless comments, unecessary diff.

   for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
 + struct stat filestat;
 +
   if (mflag  confirm(argv[0], *cpp)) {
 +
 + /* 
trailing whitespace

 +  * If file is a directory then create a new one
 +  * at the remote machine.
 +  */
 + stat(*cpp, filestat);
 +
 + if (S_ISDIR(filestat.st_mode)) {
mget() has this logic to skip on directories
if (type == 'd'  depth == max_depth)
continue;
if (!confirm(argv[0], cp))
continue;
if (type == 'd') {
Perhaps we want the same for mput()

 + char* xargv[] = {argv[0], *cpp};
terminating NULL is missing.
Make it consistent to mget() and declare at function beginning.
Then you get original argv[0], before optind has been added.

 +
 + if (depth == max_depth) {
 + continue;
 + }
no { } for one line if

 +
 + makedir(2, xargv);
These should be right before cd(), as cd() makes the error checking for
makedir().

 +
 + /*
 +  * Copy the hole directory recursivly.
 +  */
s/recursivly/recursively

 + if (chdir(*cpp) != 0) {
 + warn(local: %s, *cpp);
 + continue;
 + 

Re: ftp mput recursiv upload diff for testing

2012-07-12 Thread Jan Klemkow
I fixed the most things.

It took me a while to figure out what that code does, so I think the
comments are usefull for everybody who tries to read it.

The file type information comes from this special remglob2() function.
There is no equivalent thing in the context of mput().  So I check the
local file type with stat(2) and S_ISDIR().

The makedir() function has no return value, so it is not posible at the
moment to detect an error inside that function.

Here is the current diff.

bye,
Jan

Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  13 Jul 2012 01:10:57 -
@@ -231,15 +231,32 @@ mput(int argc, char *argv[])
extern int optind, optreset;
int ch, i, restartit = 0;
sig_t oldintr;
-   char *cmd, *tp;
+   char *cmd, *tp, *xargv[] = {argv[0], NULL, NULL};
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
 
optind = optreset = 1;
 
-   while ((ch = getopt(argc, argv, c)) != -1) {
+   if (depth)
+   depth++;
+
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s\n,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +264,8 @@ mput(int argc, char *argv[])
 
if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +336,13 @@ usage:
mflag = 0;
return;
}
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;
 
+   /* Copy files without word expansion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +368,7 @@ usage:
continue;
}
 
+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,8 +376,58 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
+   struct stat filestat;
+
if (mflag  confirm(argv[0], *cpp)) {
+
+   /*
+* If file is a directory then create a new one
+* at the remote machine.
+*/
+   stat(*cpp, filestat);
+
+   if (S_ISDIR(filestat.st_mode)) {
+
+   if (depth == max_depth)
+   continue;
+
+   xargv[1] = *cpp;
+   makedir(2, xargv);
+
+   /*
+* Copy the hole directory recursivly.
+*/
+   if (chdir(*cpp) != 0) {
+   warn(local: %s, *cpp);
+   continue;
+   }
+
+   xargv[1] = *cpp;
+   cd(2, xargv);
+   if (dirchange != 1) {
+   mflag = 0;
+   goto out;
+   }
+
+   xargv[1] = *;
+   mput(2, xargv);
+
+   xargv[1] = ..;
+   cd(2, xargv);
+

Re: ftp mput recursiv upload diff for testing

2012-07-09 Thread Jan Klemkow
Hello,

this is the same diff, but the mapage part it adaptet, for the current
version of ftp.1 in cvs.

bye,
Jan

On Thu, Jan 26, 2012 at 09:44:45PM +0100, Jan Klemkow wrote:
 On Thu, Jan 12, 2012 at 09:40:19PM +0100, Jan Klemkow wrote:
  Hello,
  
  this is my diff for recursive upload for ftp(1).
  It modifies the mput command for doing this.
  Please test it and tell me everything that is
  wrong with it.
  
  bye,
  Jan
  
 
 I test this patch on OpenBSD 5.0 sparc64.
 Man diff is improved by jmc.



Re: ftp mput recursiv upload diff for testing

2012-07-09 Thread Jan Klemkow
On Mon, Jul 09, 2012 at 02:00:11PM +0200, Jan Klemkow wrote:
 Hello,
 
 this is the same diff, but the mapage part it adaptet, for the current
 version of ftp.1 in cvs.
 
 bye,
 Jan
 
 On Thu, Jan 26, 2012 at 09:44:45PM +0100, Jan Klemkow wrote:
  On Thu, Jan 12, 2012 at 09:40:19PM +0100, Jan Klemkow wrote:
   Hello,
   
   this is my diff for recursive upload for ftp(1).
   It modifies the mput command for doing this.
   Please test it and tell me everything that is
   wrong with it.
   
   bye,
   Jan
   
  
  I test this patch on OpenBSD 5.0 sparc64.
  Man diff is improved by jmc.
 

this time with diff.

Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  9 Jul 2012 11:56:54 -
@@ -229,17 +229,30 @@ void
 mput(int argc, char *argv[])
 {
extern int optind, optreset;
-   int ch, i, restartit = 0;
+   int ch, i, restartit = 0, recursiv = 0;
sig_t oldintr;
char *cmd, *tp;
-
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
optind = optreset = 1;
 
-   while ((ch = getopt(argc, argv, c)) != -1) {
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +260,8 @@ mput(int argc, char *argv[])
 
if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +332,16 @@ usage:
mflag = 0;
return;
}
+
+   if (depth)
+   depth++;
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;
 
+   /* Copy files without word expantion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +367,7 @@ usage:
continue;
}
 
+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,8 +375,58 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
+   struct stat filestat;
+
if (mflag  confirm(argv[0], *cpp)) {
+
+   /* 
+* If file is a directory then create a new one
+* at the remote machine.
+*/
+   stat(*cpp, filestat);
+
+   if (S_ISDIR(filestat.st_mode)) {
+   char* xargv[] = {argv[0], *cpp};
+
+   if (depth == max_depth) {
+   continue;
+   }
+
+   makedir(2, xargv);
+
+   /*
+* Copy the hole directory recursivly.
+*/
+   if (chdir(*cpp) != 0) {
+   warn(local: %s, *cpp);
+   continue;
+   }
+
+   xargv[1] = *cpp;
+   cd(2, xargv);
+   if (dirchange != 1) {
+   mflag = 0;
+   goto out;
+   }
+
+   xargv[1] = *;
+

Re: ftp mput recursiv upload diff for testing

2012-01-26 Thread Jan Klemkow
On Thu, Jan 12, 2012 at 09:40:19PM +0100, Jan Klemkow wrote:
 Hello,
 
 this is my diff for recursive upload for ftp(1).
 It modifies the mput command for doing this.
 Please test it and tell me everything that is
 wrong with it.
 
 bye,
 Jan
 

I test this patch on OpenBSD 5.0 sparc64.
Man diff is improved by jmc.

Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  12 Jan 2012 20:36:32 -
@@ -229,17 +229,30 @@ void
 mput(int argc, char *argv[])
 {
extern int optind, optreset;
-   int ch, i, restartit = 0;
+   int ch, i, restartit = 0, recursiv = 0;
sig_t oldintr;
char *cmd, *tp;
-
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
optind = optreset = 1;
 
-   while ((ch = getopt(argc, argv, c)) != -1) {
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +260,8 @@ mput(int argc, char *argv[])
 
if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +332,16 @@ usage:
mflag = 0;
return;
}
+
+   if (depth)
+   depth++;
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;
 
+   /* Copy files without word expantion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +367,7 @@ usage:
continue;
}
 
+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,8 +375,58 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
+   struct stat filestat;
+
if (mflag  confirm(argv[0], *cpp)) {
+
+   /* 
+* If file is a directory then create a new one
+* at the remote machine.
+*/
+   stat(*cpp, filestat);
+
+   if (S_ISDIR(filestat.st_mode)) {
+   char* xargv[] = {argv[0], *cpp};
+
+   if (depth == max_depth) {
+   continue;
+   }
+
+   makedir(2, xargv);
+
+   /*
+* Copy the hole directory recursivly.
+*/
+   if (chdir(*cpp) != 0) {
+   warn(local: %s, *cpp);
+   continue;
+   }
+
+   xargv[1] = *cpp;
+   cd(2, xargv);
+   if (dirchange != 1) {
+   mflag = 0;
+   goto out;
+   }
+
+   xargv[1] = *;
+   mput(2, xargv);
+
+   xargv[1] = ..;
+   cd(2, xargv);
+   if (dirchange != 1) {
+   mflag = 0;
+ 

ftp mput recursiv upload diff for testing

2012-01-12 Thread Jan Klemkow

Hello,

this is my diff for recursive upload for ftp(1).
It modifies the mput command for doing this.
Please test it and tell me everything that is
wrong with it.

bye,
Jan

Index: cmds.c
===
RCS file: /cvs/src/usr.bin/ftp/cmds.c,v
retrieving revision 1.70
diff -u -p -r1.70 cmds.c
--- cmds.c  5 May 2009 19:35:30 -   1.70
+++ cmds.c  12 Jan 2012 20:36:32 -
@@ -229,17 +229,30 @@ void
 mput(int argc, char *argv[])
 {
extern int optind, optreset;
-   int ch, i, restartit = 0;
+   int ch, i, restartit = 0, recursiv = 0;
sig_t oldintr;
char *cmd, *tp;
-
+   const char *errstr;
+   static int depth = 0, max_depth = 0;
optind = optreset = 1;

-   while ((ch = getopt(argc, argv, c)) != -1) {
+   while ((ch = getopt(argc, argv, cd:r)) != -1) {
switch(ch) {
case 'c':
restartit = 1;
break;
+   case 'd':
+   max_depth = strtonum(optarg, 0, INT_MAX, errstr);
+   if (errstr != NULL) {
+   fprintf(ttyout, bad depth value, %s: %s,
+   errstr, optarg);
+   code = -1;
+   return;
+   }
+   break;
+   case 'r':
+   depth = 1;
+   break;
default:
goto usage;
}
@@ -247,7 +260,8 @@ mput(int argc, char *argv[])

if (argc - optind  1  !another(argc, argv, local-files)) {
 usage:
-   fprintf(ttyout, usage: %s [-c] local-files\n, argv[0]);
+   fprintf(ttyout, usage: %s [-cr] [-d depth] local-files\n,
+   argv[0]);
code = -1;
return;
}
@@ -318,11 +332,16 @@ usage:
mflag = 0;
return;
}
+
+   if (depth)
+   depth++;
+
for (i = 1; i  argc; i++) {
char **cpp;
glob_t gl;
int flags;

+   /* Copy files without word expantion */
if (!doglob) {
if (mflag  confirm(argv[0], argv[i])) {
tp = (ntflag) ? dotrans(argv[i]) : argv[i];
@@ -348,6 +367,7 @@ usage:
continue;
}

+   /* expanding file names */
memset(gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
if (glob(argv[i], flags, NULL, gl) || gl.gl_pathc == 0) {
@@ -355,8 +375,58 @@ usage:
globfree(gl);
continue;
}
+
+   /* traverse all expanded file names */
for (cpp = gl.gl_pathv; cpp  *cpp != NULL; cpp++) {
+   struct stat filestat;
+
if (mflag  confirm(argv[0], *cpp)) {
+
+   /*
+* If file is a directory then create  
a new one

+* at the remote machine.
+*/
+   stat(*cpp, filestat);
+
+   if (S_ISDIR(filestat.st_mode)) {
+   char* xargv[] = {argv[0], *cpp};
+
+   if (depth == max_depth) {
+   continue;
+   }
+
+   makedir(2, xargv);
+
+   /*
+* Copy the hole directory recursivly.
+*/
+   if (chdir(*cpp) != 0) {
+   warn(local: %s, *cpp);
+   continue;
+   }
+
+   xargv[1] = *cpp;
+   cd(2, xargv);
+   if (dirchange != 1) {
+   mflag = 0;
+   goto out;
+   }
+
+   xargv[1] = *;
+   mput(2, xargv);
+
+   xargv[1] = ..;
+   cd(2, xargv);
+   if (dirchange != 1) {
+   mflag = 0;
+   }
+ out:
+   if (chdir(..) != 0) {
+   warn(local: %s,