/*
* Copyright (c) 1985, 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* from: @(#)cmds.c 5.26 (Berkeley) 3/5/91
*/
char cmds_rcsid[] =
"$Id: cmds.c,v 1.33 2000/07/23 01:36:59 dholland Exp $";
/*
* FTP User Program -- Command Routines.
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/ftp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <ctype.h>
#include <limits.h> /* for PATH_MAX */
#include <time.h>
#include <string.h>
#include <unistd.h>
#ifdef __USE_READLINE__
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include "ftp_var.h"
#include "pathnames.h"
#include "cmds.h"
#include "glob.h"
void intr(int);
extern FILE *cout;
extern int data;
extern const char *home;
extern off_t restart_point;
extern char reply_string[];
static char *mname;
static sigjmp_buf jabort;
static sigjmp_buf abortprox;
static char *remglob(char *argv[], int doswitch);
static int checkglob(int fd, const char *pattern);
static char *dotrans(char *name);
static char *domap(char *name);
static char *globulize(char *str);
static int confirm(const char *cmd, const char *file);
static int getit(int argc, char *argv[], int restartit, const char *modestr);
static void quote1(const char *initial, int argc, char **argv);
/*
* pipeprotect: protect against "special" local filenames by prepending
* "./". Special local filenames are "-" and "|..." AND "/...".
*/
static char *pipeprotect(char *name)
{
char *nu;
if (strcmp(name, "-") && *name!='|' && *name!='/') {
return name;
}
/* We're going to leak this memory. XXX. */
nu = malloc(strlen(name)+3);
if (nu==NULL) {
perror("malloc");
code = -1;
return NULL;
}
strcpy(nu, ".");
if (*name != '/') strcat(nu, "/");
strcat(nu, name);
return nu;
}
/*
* Look for embedded ".." in a pathname and change it to "!!", printing
* a warning.
*/
static char *pathprotect(char *name)
{
int gotdots=0, i, len;
/* Convert null terminator to trailing / to catch a trailing ".." */
len = strlen(name)+1;
name[len-1] = '/';
/*
* State machine loop. gotdots is < 0 if not looking at dots,
* 0 if we just saw a / and thus might start getting dots,
* and the count of dots seen so far if we have seen some.
*/
for (i=0; i<len; i++) {
if (name[i]=='.' && gotdots>=0) gotdots++;
else if (name[i]=='/' && gotdots<0) gotdots=0;
else if (name[i]=='/' && gotdots==2) {
printf("Warning: embedded .. in %.*s (changing to !!)\n",
len-1, name);
name[i-1] = '!';
name[i-2] = '!';
gotdots = 0;
}
else if (name[i]=='/') gotdots = 0;
else gotdots = -1;
}
name[len-1] = 0;
return name;
}
/*
* `Another' gets another argument, and stores the new argc and argv.
* It reverts to the top level (via main.c's intr()) on EOF/error.
*
* Returns false if no new arguments have been added.
*/
int
another(int *pargc, char ***pargv, const char *prompt)
{
int margc;
char **margv;
unsigned len = strlen(line);
int ret;
if (len >= sizeof(line) - 3) {
printf("sorry, arguments too long\n");
intr(0);
}
printf("(%s) ", prompt);
line[len++] = ' ';
if (fgets(&line[len], sizeof(line) - len, stdin) == NULL)
intr(0);
len += strlen(&line[len]);
if (len > 0 && line[len - 1] == '\n')
line[len - 1] = '\0';
margv = makeargv(&margc, NULL);
ret = margc > *pargc;
*pargc = margc;
*pargv = margv;
return ret;
}
/*
* Connect to peer server and
* auto-login, if possible.
*/
void
setpeer(int argc, char *argv[])
{
char *host;
unsigned short port;
if (connected) {
printf("Already connected to %s, use close first.\n",
hostname);
code = -1;
return;
}
if (argc < 2)
(void) another(&argc, &argv, "to");
if (argc < 2 || argc > 3) {
printf("usage: %s host-name [port]\n", argv[0]);
code = -1;
return;
}
port = ftp_port;
if (argc > 2) {
port = atoi(argv[2]);
if (port < 1) {
printf("%s: bad port number-- %s\n", argv[1], argv[2]);
printf ("usage: %s host-name [port]\n", argv[0]);
code = -1;
return;
}
port = htons(port);
}
host = hookup(argv[1], port);
if (host) {
int overbose;
connected = 1;
/*
* Set up defaults for FTP.
*/
(void) strcpy(typename, "ascii"), type = TYPE_A;
curtype = TYPE_A;
(void) strcpy(formname, "non-print"), form = FORM_N;
(void) strcpy(modename, "stream"), mode = MODE_S;
(void) strcpy(structname, "file"), stru = STRU_F;
(void) strcpy(bytename, "8"), bytesize = 8;
if (autologin)
(void) dologin(argv[1]);
#if defined(__unix__) && CHAR_BIT == 8
/*
* this ifdef is to keep someone form "porting" this to an incompatible
* system and not checking this out. This way they have to think about it.
*/
overbose = verbose;
if (debug == 0)
verbose = -1;
if (command("SYST") == COMPLETE && overbose) {
register char *cp, c = 0;
cp = index(reply_string+4, ' ');
if (cp == NULL)
cp = index(reply_string+4, '\r');
if (cp) {
if (cp[-1] == '.')
cp--;
c = *cp;
*cp = '\0';
}
printf("Remote system type is %s.\n",
reply_string+4);
if (cp)
*cp = c;
}
if (!strncmp(reply_string, "215 UNIX Type: L8", 17)) {
if (proxy)
unix_proxy = 1;
else
unix_server = 1;
/*
* Set type to 0 (not specified by user),
* meaning binary by default, but don't bother
* telling server. We can use binary
* for text files unless changed by the user.
*/
type = 0;
(void) strcpy(typename, "binary");
if (overbose)
printf("Using %s mode to transfer files.\n",
typename);
} else {
if (proxy)
unix_proxy = 0;
else
unix_server = 0;
if (overbose &&
!strncmp(reply_string, "215 TOPS20", 10))
printf(
"Remember to set tenex mode when transfering binary files from this machine.\n");
}
verbose = overbose;
#else
#warning "Unix auto-mode code skipped"
#endif /* unix */
}
}
struct types {
const char *t_name;
const char *t_mode;
int t_type;
const char *t_arg;
} types[] = {
{ "ascii", "A", TYPE_A, NULL },
{ "binary", "I", TYPE_I, NULL },
{ "image", "I", TYPE_I, NULL },
{ "ebcdic", "E", TYPE_E, NULL },
{ "tenex", "L", TYPE_L, bytename },
{
netkit-ftp-0.17.tar.gz
5星 · 超过95%的资源 需积分: 15 106 浏览量
2008-04-06
09:35:10
上传
评论
收藏 53KB GZ 举报
zht_sir
- 粉丝: 103
- 资源: 41
最新资源
- 基于Matlab人脸肤色定理的教师人数统计+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab霍夫曼变换的表盘读数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab火灾烟雾检测源码带GUI界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的恶劣天气交通标志识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的霍夫曼变换的表盘示数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的车道线识别系统 +源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的教室人数统计系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB的教室人数统计系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB 的霍夫曼变换答题卡识别源码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab+bp神经网络的神经网络汉字识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论9