Makefile:

Add testftp: target
ftp.c:
  add more debugging output and fix a few more problems
media_strategy:
  make the ftp system actually do something resembling common sense.
  it now works after a fashion, although it soon falls over for some
  reason.
This commit is contained in:
Gary Palmer 1995-05-24 11:19:11 +00:00
parent 66b1d44d35
commit b2687efa65
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=8726
6 changed files with 68 additions and 41 deletions

View File

@ -91,5 +91,8 @@ makedevs.c: dev2c.sh Makefile rtermcap
rtermcap: ${.CURDIR}/rtermcap.c
${CC} -o rtermcap ${.CURDIR}/rtermcap.c -ltermcap
testftp: ftp.c
cc -o testftp -I../libdisk -DSTANDALONE_FTP ftp.c
.include <bsd.prog.mk>

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
* $Id$
* $Id: ftp.c,v 1.3 1995/05/24 09:00:19 jkh Exp $
*
*/
@ -23,6 +23,10 @@
#include <errno.h>
#include <ctype.h>
#include "ftp.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifndef STANDALONE_FTP
#include "sysinstall.h"
#endif /*STANDALONE_FTP*/
@ -66,7 +70,7 @@ get_a_line(FTP_t ftp)
if (!i)
continue;
buf[i] = '\0';
debug(ftp,"LIBFTP: received <%s>\n",buf);
debug(ftp, "LIBFTP: received <%s>\n",buf);
return buf;
}
i++;
@ -104,7 +108,7 @@ get_a_number(FTP_t ftp, char **q)
static int
botch(FTP_t ftp, char *func, char *state)
{
debug(ftp,"LIBFTP: Botch: %s called outside state %s\n",func,state);
debug(ftp, "LIBFTP: Botch: %s called outside state %s\n",func,state);
writes(ftp->fd_ctrl,"QUIT\r\n");
close(ftp->fd_ctrl); ftp->fd_ctrl = -1;
close(ftp->fd_xfer); ftp->fd_xfer = -1;
@ -123,7 +127,7 @@ cmd(FTP_t ftp, const char *fmt, ...)
(void) vsnprintf(p, sizeof p, fmt, ap);
va_end(ap);
debug(ftp,"LIBFTP: send <%s>\n",p);
debug(ftp, "LIBFTP: send <%s>\n",p);
strcat(p,"\r\n");
if (writes(ftp->fd_ctrl,p))
return -1;
@ -162,7 +166,6 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
struct sockaddr_in sin;
int s;
unsigned long temp;
extern unsigned long inet_addr(char *);
int i;
if (ftp->state != init)
@ -174,20 +177,20 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
if (!passwd)
passwd = "??@??(FreeBSD:libftp)"; /* XXX */
debug(ftp,"FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd);
debug(ftp, "FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd);
temp = inet_addr(host);
if (temp != INADDR_NONE)
{
debug(ftp,"Using dotted IP address `%s'\n", host);
debug(ftp, "Using dotted IP address `%s'\n", host);
ftp->addrtype = sin.sin_family = AF_INET;
sin.sin_addr.s_addr = temp;
} else {
debug(ftp,"Trying to resolve `%s'\n", host);
debug(ftp, "Trying to resolve `%s'\n", host);
he = gethostbyname(host);
if (!he)
{
debug(ftp,"Lookup of `%s' failed!\n", host);
debug(ftp, "Lookup of `%s' failed!\n", host);
return ENOENT;
}
ftp->addrtype = sin.sin_family = he->h_addrtype;
@ -198,12 +201,12 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
{
debug("Socket open failed: %s (%i)\n", strerror(errno), errno);
debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno);
return s;
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
debug("Connection failed: %s (%i)\n", strerror(errno), errno);
debug(ftp,"Connection failed: %s (%i)\n", strerror(errno), errno);
(void)close(s);
return -1;
}
@ -262,9 +265,10 @@ FtpGet(FTP_t ftp, char *file)
} else {
return -1;
}
if(ftp->passive) {
if (ftp->passive) {
debug(ftp, "LIBFTP: send <%s>\n","PASV");
if (writes(ftp->fd_ctrl,"PASV\r\n"))
return -1;
return -1;*/
i = get_a_number(ftp,&q);
if (i != 227)
return -1;
@ -281,12 +285,15 @@ FtpGet(FTP_t ftp, char *file)
sin.sin_family = ftp->addrtype;
bcopy(addr, (char *)&sin.sin_addr, 4);
bcopy(addr+4, (char *)&sin.sin_port, 2);
debug(ftp, "Opening active socket to %s : %u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
return -1;
debug(ftp, "Connecting to %s:%u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
(void)close(s);
debug(ftp,"connect, errno = %d\n",errno);
debug(ftp, "connect: %s (%d)\n", strerror(errno), errno);
return -1;
}
@ -328,9 +335,9 @@ main(int argc, char **argv)
if (i) err(1,"FtpOpen(%d)",i);
FtpBinary(ftp,1);
FtpPassive(ftp,1);
FtpChdir(ftp,"/pub");
FtpChdir(ftp,"/");
FtpChdir(ftp,"CTM");
i = FtpGet(ftp,"README_CTM_MOVED");
i = FtpGet(ftp,"README");
while(1 == read(i,&c,1))
putchar(c);
FtpEOF(ftp);

View File

@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
* $Id: media_strategy.c,v 1.14 1995/05/24 01:27:11 jkh Exp $
* $Id: media_strategy.c,v 1.15 1995/05/24 09:00:44 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@ -567,14 +567,18 @@ mediaGetFTP(char *dist)
while (chunk < numchunks)
{
int n;
char *buffer;
buffer = safe_malloc(1024);
char *buffer = safe_malloc(10240);
snprintf(buf, 512, "%s.%c%c", dist, (chunk / 26) + 'a', (chunk % 26) + 'a');
fd = FtpGet(ftp, buf);
if (fd < 0)
{
msgConfirm("FtpGet returned %d\n", fd);
exit(1);
}
while ((n = read(fd, buffer, 1024))>0)
while ((n = read(fd, buffer, 10240))>0)
{
retval = write(1, buffer, n);
if (retval != n)
@ -584,10 +588,10 @@ mediaGetFTP(char *dist)
exit(1);
}
close(fd);
++chunk;
}
FtpEOF(ftp);
close(fd);
++chunk;
}
close(1);
msgDebug("Extract of %s finished!!!\n", dist);

View File

@ -91,5 +91,8 @@ makedevs.c: dev2c.sh Makefile rtermcap
rtermcap: ${.CURDIR}/rtermcap.c
${CC} -o rtermcap ${.CURDIR}/rtermcap.c -ltermcap
testftp: ftp.c
cc -o testftp -I../libdisk -DSTANDALONE_FTP ftp.c
.include <bsd.prog.mk>

View File

@ -91,5 +91,8 @@ makedevs.c: dev2c.sh Makefile rtermcap
rtermcap: ${.CURDIR}/rtermcap.c
${CC} -o rtermcap ${.CURDIR}/rtermcap.c -ltermcap
testftp: ftp.c
cc -o testftp -I../libdisk -DSTANDALONE_FTP ftp.c
.include <bsd.prog.mk>

View File

@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
* $Id$
* $Id: ftp.c,v 1.3 1995/05/24 09:00:19 jkh Exp $
*
*/
@ -23,6 +23,10 @@
#include <errno.h>
#include <ctype.h>
#include "ftp.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifndef STANDALONE_FTP
#include "sysinstall.h"
#endif /*STANDALONE_FTP*/
@ -66,7 +70,7 @@ get_a_line(FTP_t ftp)
if (!i)
continue;
buf[i] = '\0';
debug(ftp,"LIBFTP: received <%s>\n",buf);
debug(ftp, "LIBFTP: received <%s>\n",buf);
return buf;
}
i++;
@ -104,7 +108,7 @@ get_a_number(FTP_t ftp, char **q)
static int
botch(FTP_t ftp, char *func, char *state)
{
debug(ftp,"LIBFTP: Botch: %s called outside state %s\n",func,state);
debug(ftp, "LIBFTP: Botch: %s called outside state %s\n",func,state);
writes(ftp->fd_ctrl,"QUIT\r\n");
close(ftp->fd_ctrl); ftp->fd_ctrl = -1;
close(ftp->fd_xfer); ftp->fd_xfer = -1;
@ -123,7 +127,7 @@ cmd(FTP_t ftp, const char *fmt, ...)
(void) vsnprintf(p, sizeof p, fmt, ap);
va_end(ap);
debug(ftp,"LIBFTP: send <%s>\n",p);
debug(ftp, "LIBFTP: send <%s>\n",p);
strcat(p,"\r\n");
if (writes(ftp->fd_ctrl,p))
return -1;
@ -162,7 +166,6 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
struct sockaddr_in sin;
int s;
unsigned long temp;
extern unsigned long inet_addr(char *);
int i;
if (ftp->state != init)
@ -174,20 +177,20 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
if (!passwd)
passwd = "??@??(FreeBSD:libftp)"; /* XXX */
debug(ftp,"FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd);
debug(ftp, "FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd);
temp = inet_addr(host);
if (temp != INADDR_NONE)
{
debug(ftp,"Using dotted IP address `%s'\n", host);
debug(ftp, "Using dotted IP address `%s'\n", host);
ftp->addrtype = sin.sin_family = AF_INET;
sin.sin_addr.s_addr = temp;
} else {
debug(ftp,"Trying to resolve `%s'\n", host);
debug(ftp, "Trying to resolve `%s'\n", host);
he = gethostbyname(host);
if (!he)
{
debug(ftp,"Lookup of `%s' failed!\n", host);
debug(ftp, "Lookup of `%s' failed!\n", host);
return ENOENT;
}
ftp->addrtype = sin.sin_family = he->h_addrtype;
@ -198,12 +201,12 @@ FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
{
debug("Socket open failed: %s (%i)\n", strerror(errno), errno);
debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno);
return s;
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
debug("Connection failed: %s (%i)\n", strerror(errno), errno);
debug(ftp,"Connection failed: %s (%i)\n", strerror(errno), errno);
(void)close(s);
return -1;
}
@ -262,9 +265,10 @@ FtpGet(FTP_t ftp, char *file)
} else {
return -1;
}
if(ftp->passive) {
if (ftp->passive) {
debug(ftp, "LIBFTP: send <%s>\n","PASV");
if (writes(ftp->fd_ctrl,"PASV\r\n"))
return -1;
return -1;*/
i = get_a_number(ftp,&q);
if (i != 227)
return -1;
@ -281,12 +285,15 @@ FtpGet(FTP_t ftp, char *file)
sin.sin_family = ftp->addrtype;
bcopy(addr, (char *)&sin.sin_addr, 4);
bcopy(addr+4, (char *)&sin.sin_port, 2);
debug(ftp, "Opening active socket to %s : %u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
return -1;
debug(ftp, "Connecting to %s:%u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
(void)close(s);
debug(ftp,"connect, errno = %d\n",errno);
debug(ftp, "connect: %s (%d)\n", strerror(errno), errno);
return -1;
}
@ -328,9 +335,9 @@ main(int argc, char **argv)
if (i) err(1,"FtpOpen(%d)",i);
FtpBinary(ftp,1);
FtpPassive(ftp,1);
FtpChdir(ftp,"/pub");
FtpChdir(ftp,"/");
FtpChdir(ftp,"CTM");
i = FtpGet(ftp,"README_CTM_MOVED");
i = FtpGet(ftp,"README");
while(1 == read(i,&c,1))
putchar(c);
FtpEOF(ftp);