1. Add verbose flag to ftp_login()

2. Remove pkg_* support - tcl7.5's channel interface has rendered this
   almost entirely unsupportable (at least in the way it currently stands).
Submitted-By: jmz & jkh
This commit is contained in:
Jordan K. Hubbard
1996-08-03 11:58:54 +00:00
parent 96a9d7fb41
commit ccdae53c9a
5 changed files with 16 additions and 306 deletions
-257
View File
@@ -1,257 +0,0 @@
/*
* Copyright (c)1995, 1996 Jordan Hubbard
*
* All rights reserved.
*
* This source code may be used, modified, copied, distributed, and
* sold, in both source and binary form provided that the above
* copyright and these terms are retained, verbatim, as the first
* lines of this file. Under no circumstances is the author
* responsible for the proper functioning of the software nor does
* the author assume any responsibility for damages incurred with
* its use.
*
* $Id: ftp_pkg.c,v 1.1.1.1 1996/06/17 12:26:06 jkh Exp $
*
* TCL Interface code for functions provided by the ftp library.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <ftpio.h>
#include "ftp_pkg.h"
#ifndef TRUE
#define TRUE (1)
#define FALSE (0)
#endif
#define CHECK_ARGS(cnt, myname, str) \
if (argc <= (cnt)) { sprintf(interp->result, "usage: %s %s", myname, str); return TCL_ERROR; }
#define USAGE(myname, msg) \
{ fprintf(stderr, "%s: %s\n", myname, msg); return TCL_ERROR; }
/* Registration function */
int
Ftp_Init(Tcl_Interp *interp)
{
Tcl_CreateCommand (interp, "ftp_login", Ftp_login, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_chdir", Ftp_chdir, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_getsize", Ftp_getsize, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_get", Ftp_get, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_put", Ftp_put, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_binary", Ftp_binary, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_passive", Ftp_passive, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_get_url", Ftp_get_url, NULL, NULL);
Tcl_CreateCommand (interp, "ftp_put_url", Ftp_put_url, NULL, NULL);
return TCL_OK;
}
/*
* ftp_login host user passwd port
* -- returns new fileId
*
*/
int
Ftp_login(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
char *user, *pass;
int port;
CHECK_ARGS(1, argv[0], "host [user] [passwd] [port]");
user = (argc > 2) ? argv[2] : "ftp";
pass = (argc > 3) ? argv[3] : "setup@";
port = (argc > 4) ? atoi(argv[4]) : 21;
/* Debug("ftp_pkg: attempt login to host %s using %s/%s (port %d)", argv[1], user, pass, port); */
fp = ftpLogin(argv[1], user, pass, port);
if (fp) {
/* Debug("ftp_pkg: logged successfully into host %s", argv[1]); */
Tcl_EnterFile(interp, fp, TCL_FILE_READABLE | TCL_FILE_WRITABLE);
return TCL_OK;
}
/* Debug("ftp_pkg: login operation failed for host %s", argv[1]); */
return TCL_ERROR;
}
/*
* ftp_chdir file-handle newdir
* -- returns status
*/
int
Ftp_chdir(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
CHECK_ARGS(2, argv[0], "fileId directory");
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
return TCL_ERROR;
/* Debug("ftp_pkg: attempt chdir to dir %s", argv[2]); */
if (!ftpChdir(fp, argv[2])) {
/* Debug("ftp_pkg: chdir successful"); */
return TCL_OK;
}
/* Debug("ftp_pkg: chdir failed"); */
return TCL_ERROR;
}
/*
* ftp_getsize file-handle filename
* -- returns size
*/
int
Ftp_getsize(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
int sz;
CHECK_ARGS(2, argv[0], "fileId filename");
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
return TCL_ERROR;
/* Debug("ftp_pkg: attempt to get size of %s", argv[2]); */
if ((sz = ftpGetSize(fp, argv[2])) >= 0) {
/* Debug("ftp_pkg: getsize successful (%d)", sz); */
sprintf(interp->result, "%d", sz);
return TCL_OK;
}
/* Debug("ftp_pkg: chdir failed"); */
return TCL_ERROR;
}
/*
* ftp_get fileId filename
* -- returns new fileId for filename
*
*/
int
Ftp_get(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp, *fp2;
CHECK_ARGS(2, argv[0], "fileId filename");
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
return TCL_ERROR;
/* Debug("ftp_pkg: attempt to get file %s", argv[2]); */
fp2 = ftpGet(fp, argv[2]);
if (fp2) {
/* Debug("ftp_pkg: get operation successful for: %s", argv[2]); */
Tcl_EnterFile(interp, fp2, TCL_FILE_READABLE);
return TCL_OK;
}
/* Debug("ftp_pkg: get operation failed for file %s", argv[2]); */
return TCL_ERROR;
}
/*
* ftp_put fileId filename
* -- returns new fileId for filename
*
*/
int
Ftp_put(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp, *fp2;
CHECK_ARGS(2, argv[0], "fileId filename");
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
return TCL_ERROR;
/* Debug("ftp_pkg: attempt to put file %s", argv[2]); */
fp2 = ftpPut(fp, argv[2]);
if (fp2) {
/* Debug("ftp_pkg: put operation successful for: %s", argv[2]); */
Tcl_EnterFile(interp, fp2, TCL_FILE_READABLE);
return TCL_OK;
}
/* Debug("ftp_pkg: put operation failed for file %s", argv[2]); */
return TCL_ERROR;
}
/*
* ftp_binary fileId value
* -- Set binary mode to truth value for FTP session represented by fileId
*
*/
int
Ftp_binary(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
CHECK_ARGS(1, argv[0], "fileId");
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
return TCL_ERROR;
/* Debug("ftp_pkg: set binary mode"); */
ftpBinary(fp);
return TCL_OK;
}
/*
* ftp_passive fileId value
* -- Set passive mode to truth value for FTP session represented by fileId
*
*/
int
Ftp_passive(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
CHECK_ARGS(2, argv[0], "fileId bool");
if (Tcl_GetOpenFile(interp, argv[1], TRUE, TRUE, &fp) != TCL_OK)
return TCL_ERROR;
/* Debug("ftp_pkg: set passive mode to %d", atoi(argv[2])); */
ftpPassive(fp, atoi(argv[2]));
return TCL_OK;
}
/*
* ftp_get_url URL user pass
* -- Return new fileId for open URL (using user and pass to log in)
*
*/
int
Ftp_get_url(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
char *user, *pass;
CHECK_ARGS(1, argv[0], "URL [username] [password]");
user = (argc > 2) ? argv[2] : "ftp";
pass = (argc > 3) ? argv[3] : "setup@";
/* Debug("ftp_pkg: attempt to get URL %s as %s/%s", argv[1], user, pass); */
fp = ftpGetURL(argv[1], user, pass);
if (fp) {
/* Debug("ftp_pkg: get URL successful"); */
Tcl_EnterFile(interp, fp, TCL_FILE_READABLE);
return TCL_OK;
}
/* Debug("ftp_pkg: get URL failed"); */
return TCL_ERROR;
}
/*
* ftp_put_url URL user pass
* -- Return new fileId for open url (using user and pass to log in)
*
*/
int
Ftp_put_url(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{
FILE *fp;
char *user, *pass;
CHECK_ARGS(1, argv[0], "URL [username] [password]");
user = (argc > 2) ? argv[2] : "ftp";
pass = (argc > 3) ? argv[3] : "setup@";
/* Debug("ftp_pkg: attempt to put URL %s as %s/%s", argv[1], user, pass); */
fp = ftpPutURL(argv[1], user, pass);
if (fp) {
/* Debug("ftp_pkg: put URL successful"); */
Tcl_EnterFile(interp, fp, TCL_FILE_READABLE);
return TCL_OK;
}
/* Debug("ftp_pkg: put URL failed"); */
return TCL_ERROR;
}
-35
View File
@@ -1,35 +0,0 @@
#ifndef _FTP_PKG_H
#define _FTP_PKG_H
/*
* Copyright (c)1995, 1996 Jordan Hubbard
*
* All rights reserved.
*
* This source code may be used, modified, copied, distributed, and
* sold, in both source and binary form provided that the above
* copyright and these terms are retained, verbatim, as the first
* lines of this file. Under no circumstances is the author
* responsible for the proper functioning of the software nor does
* the author assume any responsibility for damages incurred with
* its use.
*
* $Id$
*
* TCL Interface code for functions provided by the ftp library.
*/
#include <tcl.h>
#include <ftpio.h>
extern int Ftp_login (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_chdir (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_getsize (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_get (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_put (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_binary (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_passive (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_get_url (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
extern int Ftp_put_url (ClientData clientData, Tcl_Interp *interp, int argc, char **argv);
#endif /* _FTP_PKG_H */
+6 -5
View File
@@ -43,7 +43,7 @@
.Sh SYNOPSIS
.Fd #include <ftpio.h>
.Ft FILE *
.Fn ftpLogin "char *host, char *user, char *passwd, int ftp_port"
.Fn ftpLogin "char *host" "char *user" "char *passwd" "int ftp_port" "int verbose"
.Ft int
.Fn ftpChdir "FILE *stream, char *dirname"
.Ft int
@@ -75,12 +75,13 @@ These functions implement a high-level library for managing FTP connections.
.Fn ftpLogin
attempts to log in using the supplied
.Fa user ,
.Fa passwd
and
.Fa passwd,
.Fa ftp_port
fields (if passed as 0,
(if passed as 0,
.Fa ftp_port
defaults to the standard ftp port of 21). If it is successful, a
defaults to the standard ftp port of 21) and
.Fa verbose
fields. If it is successful, a
standard stream descriptor is returned which should be passed to
subsequent FTP operations. On failure, NULL is returned and
.Fn ftpErrno
+8 -7
View File
@@ -14,7 +14,7 @@
* Turned inside out. Now returns xfers as new file ids, not as a special
* `state' of FTP_t
*
* $Id: ftpio.c,v 1.7 1996/06/22 21:43:54 jkh Exp $
* $Id: ftpio.c,v 1.8 1996/07/04 00:55:20 jkh Exp $
*
*/
@@ -57,7 +57,7 @@ static __inline char *get_a_line(FTP_t ftp);
static int get_a_number(FTP_t ftp, char **q);
static int botch(char *func, char *botch_state);
static int cmd(FTP_t ftp, const char *fmt, ...);
static int ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port);
static int ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int verbose);
static int ftp_file_op(FTP_t ftp, char *operation, char *file, FILE **fp, char *mode, int *seekto);
static int ftp_close(FTP_t ftp);
static int get_url_info(char *url_in, char *host_ret, int *port_ret, char *name_ret);
@@ -231,7 +231,7 @@ ftpGet(FILE *fp, char *file, int *seekto)
/* Returns a standard FILE pointer type representing an open control connection */
FILE *
ftpLogin(char *host, char *user, char *passwd, int port)
ftpLogin(char *host, char *user, char *passwd, int port, int verbose)
{
FTP_t n;
FILE *fp;
@@ -241,7 +241,7 @@ ftpLogin(char *host, char *user, char *passwd, int port)
n = ftp_new();
fp = NULL;
if (n && ftp_login_session(n, host, user, passwd, port) == SUCCESS) {
if (n && ftp_login_session(n, host, user, passwd, port, verbose) == SUCCESS) {
fp = funopen(n, ftp_read_method, ftp_write_method, NULL, ftp_close_method); /* BSD 4.4 function! */
fp->_file = n->fd_ctrl;
}
@@ -289,7 +289,7 @@ ftpGetURL(char *url, char *user, char *passwd)
fp = NULL;
}
if (get_url_info(url, host, &port, name) == SUCCESS) {
fp = ftpLogin(host, user, passwd, port);
fp = ftpLogin(host, user, passwd, port, 0);
if (fp) {
fp2 = ftpGet(fp, name, NULL);
return fp2;
@@ -311,7 +311,7 @@ ftpPutURL(char *url, char *user, char *passwd)
fp = NULL;
}
if (get_url_info(url, host, &port, name) == SUCCESS) {
fp = ftpLogin(host, user, passwd, port);
fp = ftpLogin(host, user, passwd, port, 0);
if (fp) {
fp2 = ftpPut(fp, name);
return fp2;
@@ -550,7 +550,7 @@ cmd(FTP_t ftp, const char *fmt, ...)
}
static int
ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port)
ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port, int verbose)
{
struct hostent *he = NULL;
struct sockaddr_in sin;
@@ -600,6 +600,7 @@ ftp_login_session(FTP_t ftp, char *host, char *user, char *passwd, int port)
ftp->fd_ctrl = s;
ftp->con_state = isopen;
ftp->is_verbose = verbose;
i = cmd(ftp, "USER %s", user);
if (i >= 300 && i < 400)
+2 -2
View File
@@ -20,7 +20,7 @@
* Turned inside out. Now returns xfers as new file ids, not as a special
* `state' of FTP_t
*
* $Id: ftpio.h,v 1.4 1996/06/26 20:31:11 gpalmer Exp $
* $Id: ftpio.h,v 1.5 1996/07/04 00:55:21 jkh Exp $
*/
/* Internal housekeeping data structure for FTP sessions */
@@ -37,7 +37,7 @@ typedef struct {
} *FTP_t;
/* Exported routines - deal only with FILE* type */
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port);
extern FILE *ftpLogin(char *host, char *user, char *passwd, int port, int verbose);
extern int ftpChdir(FILE *fp, char *dir);
extern int ftpErrno(FILE *fp);
extern size_t ftpGetSize(FILE *fp, char *file);