Exemple #1
0
int ftp_receive_file(char *filename, char *command)
{
	int rc,state;
	int dtp=E_REFUSE;

	if (ftp_use_port!='Y') { dtp = ftp_passive_connect(); }
/*	if (dtp==E_REFUSE) { dtp = ftp_listen_connect(); } */
	if (dtp==E_REFUSE) { dtp = ftp_port_connect(); }
	if (dtp>=0) {
		rc = news_send_command( fpi, command );
/*		rc=CNbyte_count(dtp);
		fprintf( log, "Pre-Listen CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
*/
		if (CNbyte_count( dtp )==E_LISTEN) {
			if ((state=ftp_listen( dtp ))>=0) {	state = E_NORMAL; }
		} else {
			state = TCP_wait_state( dtp, TESTABLISH, 15 );
		}
		if (state==E_NORMAL) {
			rc = ftp_receive_continuations( fpi, "dummy", FALSE );
			rc = news_receive( dtp, filename, 2 );
		} else {
			fprintf( log, "TCP_wait_state returns %s \n", get_err_text(state));
			rc=CNbyte_count(dtp);
			fprintf( log, "CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
			rc = state;
		}
		TCP_close( dtp, 5 );	/* wait for connection to close */
	} else {
		fprintf( log, "open_connection returns %s \n", get_err_text(dtp));
		rc = dtp;
	}
	return(rc);
}
/***************************************************************************************************************************
**函数名称:	 	lwipServiceInit
**函数功能:	 	
**入口参数:
**返回参数:
***************************************************************************************************************************/
void lwipServiceInit(void)
{
#if(APP_FTP == APP_WHAT)
	#if(LWIP_API == WHAT_API)
	ftp_info.attri = eLWIP;
	#elif(RAW_API == WHAT_API)
	
	ftp_func.p_ftp_accept = ftp_accpet;
	ftp_func.p_ftp_bind = ftp_bind;
	ftp_func.p_ftp_connect = ftp_connect;
	ftp_func.p_ftp_listen = ftp_listen;
	ftp_func.p_ftp_new = ftp_new;
	ftp_func.p_ftp_writeData = ftp_writeData;
	ftp_func.p_ftp_arg = ftp_arg;
	
	ftp_info.attri = eRAW;
	ftp_info.ctrOrMsg = eCtr;
	ftp_info.accept = ftp_accept_fn;
	
	ftp_new(&ftp_info);
	ftp_bind(&ftp_info,21);
	ftp_listen(&ftp_info);
	ftp_accpet(&ftp_info);
	
	ftpd_init(&ftp_info,&ftp_func);
	#else
	
	#endif
#else
	
#endif	
}
Exemple #3
0
int ftp_send_file(char *filename, char *command)
{
	int rc,state,x;
	size_t bytes,total=0,timeout;
	char buff[512];
	FILE *fid;
	int dtp=E_REFUSE;

	if (ftp_use_port!='Y') { dtp = ftp_passive_connect(); }
/*	if (dtp==E_REFUSE) { dtp = ftp_listen_connect(); } */
	if (dtp==E_REFUSE) { dtp = ftp_port_connect(); }
	if (dtp>=0) {
		rc= ftp_allocate(filename);
		rc= news_send_command( fpi, command );
/*		rc=CNbyte_count(dtp);
		fprintf( log, "Pre-Listen CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
*/
		if (CNbyte_count( dtp )==E_LISTEN) {
			if ((state=ftp_listen( dtp ))>=0) { state = E_NORMAL; }
		} else {
			state = TCP_wait_state( dtp, TESTABLISH, 15 );
		}
		if (state==E_NORMAL) {
			rc = ftp_receive_continuations( fpi, "dummy", FALSE );
			fid = fopen( filename, "rb" );
			if (fid!=NULL) {
				while ((bytes=fread( buff, 1, 512, fid))>0) {
					timeout=clock()+max_to*CLK_TCK;	/* timeout */
					do {
						x = TCP_send( dtp, buff, (int16)bytes );
						if (x!=0) {
							if (clock()>timeout) {
								if (x==E_OBUFFULL) { bytes=-FTP_OBUFF_SIZE; }
								x=E_CNTIMEOUT;
							}
						}
						if (handle_escape_events()==27) { x=E_USERTIMEOUT; }
 
					/*	if (Bconstat(2)==-1 && (Bconin(2) & 0xFF)==27) { /* Esc key */
					/*		x=E_USERTIMEOUT; } */
					} while (x==E_OBUFFULL);	/* retry if 'Output Buffer full */
					total+=bytes;
					browser->msg_status(8, total);
					if (x<0) {
						fprintf( log, "TCP_send returns %s \n", get_err_text(x));
						browser->msg_status(0, x);
						break;
					}
				}
				fclose( fid );
			}
		} else {
			fprintf( log, "TCP_wait_state returns %s \n", get_err_text(state));
			rc=CNbyte_count(dtp);
			fprintf( log, "CNbyte_count returns %d, %s \n", rc, get_err_text(rc));
			rc = state;
		}
		TCP_close( dtp, 5 );	/* wait for connection to close */
	} else {
		fprintf( log, "open_connection returns %s \n", get_err_text(dtp));
		rc = dtp;
	}
	return(rc);
}