changeset 1169:ab7f336bfe52 draft

Noticed a few differences from standard help messages, plus a small problem with the port number handling: when no port was specified, it failed. The solution ended up dropping a couple lines.
author Isaac Dunham <ibid.ag@gmail.com>
date Fri, 27 Dec 2013 08:36:03 -0600
parents fbe6804a3f33
children 8afe1fde9314
files toys/pending/ftpget.c
diffstat 1 files changed, 10 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/toys/pending/ftpget.c	Fri Dec 27 08:30:32 2013 -0600
+++ b/toys/pending/ftpget.c	Fri Dec 27 08:36:03 2013 -0600
@@ -5,15 +5,15 @@
  *
  * No Standard.
  * 
-USE_FTPGET(NEWTOY(ftpget, "<2cvu:p:P:", TOYFLAG_BIN))
-USE_FTPGET(OLDTOY(ftpput,ftpget, "<2vu:p:P:", TOYFLAG_BIN))
+USE_FTPGET(NEWTOY(ftpget, "<2cvu:p:P#<0=21>65535", TOYFLAG_BIN))
+USE_FTPGET(OLDTOY(ftpput,ftpget, "<2vu:p:P#<0=21>65535", TOYFLAG_BIN))
 
 config FTPGET
   bool "ftpget/ftpput"
   default n
   help
-    usage: ftpget [-cv] [-u username -p password -P PortNumber] HOST_NAME [LOCAL_FILENAME] REMOTE_FILENAME
-    usage: ftpput [-v] [-u username -p password -P PortNumber] HOST_NAME [REMOTE_FILENAME] LOCAL_FILENAME
+    usage: ftpget [-cv] [-u USER -p PASSWORD -P PORT] HOST_NAME [LOCAL_FILENAME] REMOTE_FILENAME
+    usage: ftpput [-v] [-u USER -p PASSWORD -P PORT] HOST_NAME [REMOTE_FILENAME] LOCAL_FILENAME
 
     ftpget - Get a remote file from FTP.
     ftpput - Upload a local file on remote machine through FTP.
@@ -22,13 +22,13 @@
     -v Verbose.
     -u User name.
     -p Password.
-    -P Port Number.
+    -P Port Number (default 21).
 */
 #define FOR_ftpget
 #include "toys.h"
 
 GLOBALS(
-  char *port;
+  long port; //  char *port;
   char *password;
   char *username;
 
@@ -129,18 +129,17 @@
 static void get_sockaddr(char *host)
 {  
   struct addrinfo hints, *result;
-  char *ptr;
-  int status, port;
+  char *ptr, port[6];
+  int status;
   
   errno = 0;
-  port = strtoul(TT.port, &ptr, 10);
-  if (errno || port > 65535) error_exit("Invalid port, Range is [0-65535]");
+  snprintf(port, 6, "%ld", TT.port);
 
   memset(&hints, 0 , sizeof(struct addrinfo));
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = SOCK_STREAM;
 
-  status = getaddrinfo(host, TT.port, &hints, &result); 
+  status = getaddrinfo(host, port, &hints, &result); 
   if (status) error_exit("bad address '%s' : %s", host, gai_strerror(status));
 
   memcpy(TT.buf, result->ai_addr, result->ai_addrlen);
@@ -272,7 +271,6 @@
   if (!(toys.optflags & FLAG_u) && !(toys.optflags & FLAG_p))
     TT.username = TT.password ="anonymous";
 
-  if (!(toys.optflags & FLAG_P)) TT.port = "ftp"; //use default ftp port 21.
   //if continue is not in the command line argument.
   if (TT.isget && !(toys.optflags & FLAG_c)) TT.c = 0;