⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tinyftp.c

📁 ADAM2 sources (modified by Oleg)
💻 C
📖 第 1 页 / 共 3 页
字号:
				((req_ipaddress>>8) & 0xff),				(req_ipaddress & 0xff));			sys_setenv("my_ipaddress", cp);			rxpacket.data = req_ipaddress;		}		udp_send(rcv_ipaddress, sizeof(autodetectPacket), &rxpacket);	} }}int adam2Autodetect(void){	if (!udplib_init(sin_lclINAddr)) return 0;	if (!udplib_open(5035, 5035, autodetect_Handler)) return 0;	return 1;}#endif /* FTP_SERVER_SUPPORT *//*****************************************************************************************/#ifdef FTP_CLIENT_SUPPORTint datainbound;short ftp_rcvState;#define ftp_StateGETCMD     0       /* get a command from the user */#define ftp_StateIDLE       1       /* idle connection */#define ftp_StateINCOMMAND  2       /* command sent, awaiting response */#define ftp_StateRCVRESP    3       /* received response, need more data */char *ftp_script[8];int ftp_scriptline;BOOL ftp_echoMode;void ftp_ctlHandler (tcp_Socket *s, byte *dp, int len, int state){  	byte c, *bp, data[80];  	int i;  	if (state == SOPEN)    	return;  	if (dp == 0)     {    	tcp_Abort(&ftp_data);    	return;    }  	do     {    	i = len;    	if ( i > sizeof data )       		i = sizeof data;    	MoveW(dp, data, i);    	dp += i;    	len -= i;    	bp = data;    	while ( i-- > 0 )       	{      		c = *bp++;      		if ( c != '\r' )         	{        		if ( c == '\n' )           		{          			ftp_cmdbuf[ftp_cmdbufi] = 0;          			ftp_commandLine();          			ftp_cmdbufi = 0;          		}          		else           		{          			if ( ftp_cmdbufi < ((sizeof ftp_cmdbuf)-1) )             		{            			ftp_cmdbuf[ftp_cmdbufi++] = c;            		}          		}        	}      	}    }while(len > 0);}void ftp_commandLine(void){  	char anum[10], *sp, *dp;  	int i;  	dp = anum;  	sp = (char *)ftp_cmdbuf;  	while ((*sp == ' ') && (*sp == '\t'))     	sp++;  	i = 0;  	while (( i< ((sizeof anum) - 1)) && (*sp >= '0') && (*sp <= '9'))    	*dp++ = *sp++;  	*dp = 0;  	i = atol(anum);  	if ((i == 553) || (i == 450) || (i == 550) || (i == 425) || (i == 426) ||       	(i == 451) || (i == 500) || (i == 501) || (i == 421) || (i == 530))		sys_printf("> %s\n", ftp_cmdbuf);	    switch (ftp_rcvState) 	{    	case ftp_StateIDLE:        	if (ftp_cmdbuf[3] == '-')            	ftp_rcvState = ftp_StateRCVRESP;        	break;     	case ftp_StateINCOMMAND:        	if ( ftp_cmdbuf[3] == '-' )            	ftp_rcvState = ftp_StateRCVRESP;			     	case ftp_StateRCVRESP:        	if ( ftp_cmdbuf[3] == ' ' )            	ftp_rcvState = ftp_StateIDLE;        	break;    }}void ftp_Abort(void){	tcp_Abort(&ftp_ctl);	tcp_Abort(&ftp_data);}void ftp_application(void){    char *s;    char *dp;    int i;    char achar;    i = -1;    if (SioInCharCheck(&achar))     {      	i = achar & 0177;      			if ( i == ('C' & 037) ) 		{        	tcp_Close(&ftp_ctl);        }   	}    switch (ftp_rcvState)     {      	case ftp_StateGETCMD: getcmd:	if ( i != -1 ) 			{            	ftp_outbuf[ftp_outbuflen] = 0;            	switch (i) 				{                	case 'H' & 037:                	case 0177:                    	if ( ftp_outbuflen > 0 ) 						{                        	ftp_outbuflen--;                        	sys_printf("\010 \010");                    	}                    	break;                	case 'R' & 037:                    	if ( ftp_echoMode )                        	sys_printf("\nFtpCmd> %s", ftp_outbuf);                    	break;                	case 033:                    	ftp_echoMode = ! ftp_echoMode;                    	break;                	case '\r':                	case '\n':                    	SioOutChar('\n');                    	dp = (char *)&ftp_outbuf[ftp_outbuflen];                    	goto docmd;                	default:                    	if ( i >= ' ' && ftp_outbuflen < sizeof ftp_outbuf ) 						{                        	ftp_outbuf[ftp_outbuflen++] = i;                        	if ( ftp_echoMode ) SioOutChar(i);                    	}            	}        	}        	break;      	case ftp_StateIDLE:        	if ( ftp_scriptline < 0 ) 			{            	ftp_rcvState = ftp_StateGETCMD;            	ftp_echoMode = TRUE;	            ftp_outbuflen = 0;    	        sys_printf("FtpCmd> ");        	    goto getcmd;        	}	        if (datainbound)     /*Don't process commands whiles data is inbound!!*/		        return;        	s = ftp_script[ftp_scriptline];	        if ( s == NULL )    	        break;        	ftp_scriptline++;        	dp = (char *)ftp_outbuf;	        while (( *dp++ = *s++ ));        	dp--;docmd: 		*dp++ = '\r';        	*dp++ = '\n';        	ftp_outbuflen = (int)dp - (int)ftp_outbuf;        	ftp_outbufix = 0;        	ftp_rcvState = ftp_StateINCOMMAND;        	/* fall through */			    	case ftp_StateINCOMMAND:	        i = ftp_outbuflen - ftp_outbufix;    	    if ( i > 0 ) 			{            	i = tcp_Write(&ftp_ctl, &ftp_outbuf[ftp_outbufix], i);            	ftp_outbufix += i;            	tcp_Flush(&ftp_ctl);        	}        	/* fall through */    	case ftp_StateRCVRESP:        	break;    }}void ftp(in_HwAddress host, in_HwAddress my_ipval, char *user, char *pass, char *cwd, char *fn, procref dataHandler){    word port;    char filecmd[80];    char portcmds[80];    int index;    index = 0;    port = (sed_lclEthAddr[2] + rtim) | 0x8000;    if (fn) 	{        /* set up the script for this session */        ftp_script[index++] = user;        ftp_script[index++] = pass;        if (strlen(cwd))        	ftp_script[index++] = cwd;        ftp_script[index++] = "type i";        sys_sprintf(portcmds,"port %d,%d,%d,%d,%d,%d",                (my_ipval>>24)&0x0ff,                (my_ipval>>16)&0x0ff,                (my_ipval>> 8)&0x0ff,                (my_ipval    )&0x0ff,                ((port>>8)&0x0ff),                (port&0x0ff));        ftp_script[index++] = portcmds;        sys_sprintf(filecmd, "retr %s", fn);        ftp_script[index++] = filecmd;        ftp_script[index++] = "quit";        ftp_script[index++] = 0;        ftp_scriptline = 0;    } 	else 	{        ftp_scriptline = -1;        /* interactive mode */        ftp_echoMode = TRUE;    }    /* set up state variables */    ftp_rcvState = ftp_StateRCVRESP;    ftp_cmdbufi = 0;    tcp_Listen(&ftp_data, port, dataHandler, 0);    tcp_Open(&ftp_ctl, port, host, 21, ftp_ctlHandler);#ifndef DHCP_SUPPORT	tcp(ftp_application);#else    tcp_receive(ftp_application);#endif}static char inseq[]="0123456789-=\\`!@#$\%^&*()_+|~qwertyuiop[]QWERTYUIOP{}asdfghjkl;'ASDFGHJKL:\"zxcvbnm,./ZXCVBNM<>?";void getpass(char *str, char *rpass, int len){  	char achar;  	*rpass = 0;  	sys_printf("%s ",str);  	if (len==0) return;  	len--;  	do    {    	achar=getch();    	if ((achar!='\015')&&(achar!='\n'))      	{      		sys_printf("*");      		if (len)        	{        		*rpass++=achar;        		len--;        		*rpass=0;	        }      	}    }while((achar!='\015') && (achar!='\n'));  	sys_printf("\n");}int encrypt(char *inp, char *outp){  	int j,i,modo;  	char *cp;  	j = 0;  	*outp=0;  	modo = strlen(inseq);  	*outp++='~';  	while(*inp)    {    	j++;    	i = 0;    	cp = inseq;    	while(*cp != *inp)      	{      		i++;      		cp++;      	}    	if (!(*cp))       		return(FALSE);     	i += 10 + (j * 2);    	i = i % modo;    	*outp++ = inseq[i];    	*outp = 0;    	inp++;    }  	return(TRUE);}/*NOTE:gg30e application specific: * this decrypt implementation is copied and used as such in  * vng/pform/gg30e/hardware/adam_if.c file. * Any updates to this function here need to be reflected in  * that file too*/int decrypt(char *inp, char *outp){  	int j, i, modo;  	char *cp;  	j = 0;  	*outp = 0;  	modo = strlen(inseq);  	if (*inp++ != '~')    	return(FALSE);  	while(*inp)    {    	j++;    	i = 0;    	cp = inseq;    	while(*cp != *inp)      	{      		i++;      		cp++;      	}    	if (!(*cp))       		return(FALSE);     	i += modo - (10 + (j * 2));    	i = i % modo;    	*outp++ = inseq[i];    	*outp = 0;    	inp++;    }  	return(TRUE);}int newpass(void){  	char pass[31], pass1[30], pass2[30];  	getpass("   Enter Password:", pass1, sizeof pass1);  	getpass("Re-Enter Password:", pass2, sizeof pass2);	  	if (strcmp(pass1, pass2)!=0)	{		sys_printf("Passwords are not the same.\n");		return(1);	}  	if (strlen(pass1) < 4) 	{		sys_printf("Password to small, must be at least 4 characters.\n");		return(1);	}		  	if (!encrypt(pass1, pass))	{		sys_printf("Cannot encrypt password.\n");		return(1);	}  		sys_setenv("remote_pass", pass);  	return(0);}#endif /* FTP_CLIENT_SUPPORT */#if 0#define isprint(a) ((a >=' ')&&(a <= '~'))void xdump (byte *cp, int length, char *prefix){    int col, count;    byte prntBuf[120];    char  *pBuf = (char *)prntBuf;    count = 0;    while(count < length)	{        pBuf += sys_sprintf( pBuf, "%s", prefix );        for(col = 0;count + col < length && col < 16; col++){            if (col != 0 && (col % 4) == 0)                pBuf += sys_sprintf( pBuf, " " );            pBuf += sys_sprintf( pBuf, "%02X ", cp[count + col] );        }        while(col++ < 16)		{      			/* pad end of buffer with blanks */            if ((col % 4) == 0)                sys_sprintf( pBuf, " " );            pBuf += sys_sprintf( pBuf, "   " );        }        pBuf += sys_sprintf( pBuf, "  " );        		for(col = 0;count + col < length && col < 16; col++)		{            if (isprint((int)cp[count + col]))                pBuf += sys_sprintf( pBuf, "%c", cp[count + col] );            else                pBuf += sys_sprintf( pBuf, "." );        }        sys_sprintf( pBuf, "\n" );        sys_printf((char *)prntBuf);        count += col;        pBuf = (char *)prntBuf;    }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -