FTPget


#1

if who have a working code, show me please


#2

The sample code provided by wavecom is actually sufficient but there is working code in this forum aswell but I think its comments are in spanish


#3

Hi Her is some that I wrote last year to explain DOTA
I hope it still works (have not used it this year)

/*
Dota By Walter Senekal 26 October 2005
Explained Ftp upload and FTP Download
*/
#include "adl_global.h"
#include "ed_common.h"
#include "ed_dialup.h"
#include "ed_ftp.h"
#include "ed_gprs.h"
#include "ed_socket.h"
#include "ed_msgcodes.h"
/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStack                                                      */
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
u32 wm_apmCustomStack [ 4000 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );
/***************************************************************************/
/*  Local variables                                                        */
/***************************************************************************/
ed_FTPSetupParams_t FTPParams;
ed_gprsSetupParams_t APNParams;
ed_FTPPutFileParams_t FTPPutFileParams;
ed_FTPPutFileParams_t FTPGetFileParams;
s32 Cell_Handle;
s32 S32Return;
/***************************************************************************/
/*  Local functions                                                        */
/***************************************************************************/

void dotted_notation(unsigned long int hex_ip)
{
	ascii array[30];
	TRACE( ( 1, "Inside dotted_Notation" ) );
	if (hex_ip==0x00000000)
		return;
	else
	{
		dotted_notation(hex_ip>>8 );
		sprintf(array,"%d.",hex_ip & 0xFF);
		adl_atSendResponse(ADL_AT_RSP,array);
	}
}

u16 FTPGetDataHandler(u16 DataLen, u8 *pBData, TeDHandle id)
{
	TRACE( ( 1, "Inside FTPgetDataHandler" ) );
	TRACE((1,"Datalen=%d",DataLen));
    if ( DataLen && pBData )
    {
        if (adl_adWrite(Cell_Handle,DataLen,(void*)pBData)!=OK) 
		{
			TRACE((1,"Cannot Write To Cell"));
        }
		else
		{
			TRACE((1,"Successfully Written To Cell"));
		}
    }
    // Always acknowledge all data
    return DataLen;
}

void FTPGetRspHandler(s32 ResponseCode, TeDHandle id)
{
	TRACE( ( 1, "Inside FTPgetRspHandler" ) );
	TRACE((1,"handler response code: %d",ResponseCode));
	switch(ResponseCode) 
	{
	case ED_OK_FILE_TRANSFERED:
		TRACE(( 1,"ED_OK_FILE_TRANSFERED"));
		adl_adFinalise(Cell_Handle);
		adl_atSendResponse(ADL_AT_UNS,"Installing New App");
		S32Return=adl_adInstall(Cell_Handle);
		TRACE((1,"Install return code: %d",S32Return));
		break;
	case ED_INFO_DATA_BEGIN:
		TRACE(( 1,"ED_INFO_DATA_BEGIN"));
		break;
	case ED_ERR_DISTANT_DNS:
		TRACE(( 1,"ED_ERR_DISTANT_DNS"));
		break;
	case ED_ERR_STACK_INTERNAL:
		TRACE( ( 1,"ED_ERR_STACK_INTERNAL"));
		break;
	case ED_ERR_DISTANT_NO_RESP:
		TRACE( ( 1,"ED_ERR_DISTANT_NO_RESP"));
		break;
	case ED_ERR_DISTANT_OPEN:
		TRACE( ( 1,"ED_ERR_DISTANT_OPEN"));
		break;
	case ED_ERR_DISTANT_CD:
		TRACE( ( 1,"ED_ERR_DISTANT_CD"));
		break;
	case ED_ERR_DISTANT_CLOSE:
		TRACE( ( 1,"ED_ERR_DISTANT_CLOSE"));
		break;
	case ED_ERR_DISTANT_TCP_CLOSED:
		TRACE( ( 1,"ED_ERR_DISTANT_TCP_CLOSED"));
		break;
	case ED_ERR_DISTANT_TCP_CLOSED_BY_PEER:
		TRACE( ( 1,"ED_ERR_DISTANT_TCP_CLOSED_BY_PEER"));
		break;
	case ED_ERR_DISTANT_USERNAME:
		TRACE( ( 1,"ED_ERR_DISTANT_USERNAME"));
		break;
	case ED_ERR_DISTANT_PASSWORD:
		TRACE( ( 1,"ED_ERR_DISTANT_PASSWORD"));
		break;
	case ED_ERR_NETWORK_KO:
		TRACE( ( 1,"ED_ERR_NETWORK_KO"));
		break;
	case ED_ERR_DISTANT_DATA_RETR:
		TRACE( ( 1,"ED_ERR_DISTANT_DATA_RETR"));
		break;
		case ED_ERR_GPRS_SESSION_LOST:
		TRACE( ( 1,"ED_ERR_GPRS_SESSION_LOST"));
		break;
	}
}

void WaitFtpFileSend(u8 ID)
{
	s8 RetS8;
	ascii Temp[255];
	ascii *Mydata;
	TRACE( ( 1, "Inside WaitFTPFileSend" ) );
	wm_sprintf(Mydata,"WALTER_WALTER_WALTER_WALTER_WALTER_WALTER_WALTER");
	RetS8 =ed_SendDataExt(Mydata, wm_strlen(Mydata), FALSE, ED_ID_FTP_PUT);
	wm_sprintf(Temp,"Ret Code for edSendDataExt: %d",RetS8);
	TRACE((1,Temp));
}

void TCPPutSendDataTimer(u8 ID)
{
	s8 RetS8;
	ascii Temp[255];
	ascii Mydata[50];
	TRACE( ( 1, "TCPPutSendDataTimer" ) );
	wm_sprintf(Mydata,"WALTER_WALTER_WALTER_WALTER_WALTER_WALTER_WALTER");
	RetS8 =ed_SendDataExt(Mydata, wm_strlen(Mydata), TRUE, ED_ID_FTP_PUT);
	wm_sprintf(Temp,"Ret Code for edSendDataExt: %d",RetS8);
	TRACE((1,Temp));
}

void FTPPutRspHandler(s32 ResponseCode, TeDHandle id)
{
	s8 RetS8;
	ascii Temp[255];
	TRACE( ( 1, "Inside FTPPutRspHandler" ) );
	TRACE((1,"handler response code: %d",ResponseCode));
	switch(ResponseCode) 
	{
	case ED_OK_FILE_TRANSFERED:
		TRACE(( 1,"ED_OK_FILE_TRANSFERED"));
		ed_FTPGetFileGetConfig(&FTPGetFileParams);
		TRACE((1,"filename"));
		wm_strcpy(FTPGetFileParams.FtpPutFilename,"Hello.dwl");
		TRACE((1,"path"));
		wm_strcpy(FTPGetFileParams.FtpPutPath,".");
		TRACE((1,"FTPGetFileSetConfig"));
		RetS8=ed_FTPGetFileSetConfig(&FTPGetFileParams);
		wm_sprintf(Temp,"%d",RetS8);
		TRACE((1,Temp));
		adl_atSendResponse(ADL_AT_UNS,"\r\nGet File\r\n");
		ed_FTPGet(FTPGetRspHandler,FTPGetDataHandler);
		break;
	case ED_INFO_WAITING_FOR_DATA:
		adl_tmrSubscribe(FALSE,50,ADL_TMR_TYPE_100MS,TCPPutSendDataTimer);
		break;
	case ED_ERR_DISTANT_DNS:
		TRACE(( 1,"ED_ERR_DISTANT_DNS"));
		break;
	case ED_ERR_STACK_INTERNAL:
		TRACE( ( 1,"ED_ERR_STACK_INTERNAL"));
		break;
	case ED_ERR_DISTANT_NO_RESP:
		TRACE( ( 1,"ED_ERR_DISTANT_NO_RESP"));
		break;
	case ED_ERR_DISTANT_OPEN:
		TRACE( ( 1,"ED_ERR_DISTANT_OPEN"));
		break;
	case ED_ERR_DISTANT_CD:
		TRACE( ( 1,"ED_ERR_DISTANT_CD"));
		break;
	case ED_ERR_DISTANT_SEND:
		TRACE( ( 1,"ED_ERR_DISTANT_SEND"));
		break;
	case ED_ERR_DISTANT_CLOSE:
		TRACE( ( 1,"ED_ERR_DISTANT_CLOSE"));
		break;
	case ED_ERR_DISTANT_TCP_CLOSED:
		TRACE( ( 1,"ED_ERR_DISTANT_TCP_CLOSED"));
		break;
	case ED_ERR_DISTANT_TCP_CLOSED_BY_PEER:
		TRACE( ( 1,"ED_ERR_DISTANT_TCP_CLOSED_BY_PEER"));
		break;
	case ED_ERR_DISTANT_USERNAME:
		TRACE( ( 1,"ED_ERR_DISTANT_USERNAME"));
		break;
	case ED_ERR_DISTANT_PASSWORD:
		TRACE( ( 1,"ED_ERR_DISTANT_PASSWORD"));
		break;
	case ED_ERR_NETWORK_KO:
		TRACE( ( 1,"ED_ERR_NETWORK_KO"));
		break;
	case ED_ERR_GPRS_SESSION_LOST:
		TRACE( ( 1,"ED_ERR_GPRS_SESSION_LOST"));
		break;
	}
}

void FTPPutDataHandler(u16 MaxLen, TeDHandle id)
{
	TRACE( ( 1, "Inside FTPDataHandler" ) );
	TRACE((1,"maxsize=%d",MaxLen));		
}

void dialupHandler( s32 responseCode)
{
	s8 RetS8;
	ascii Temp[255];
	ed_dialupIPInfos_t ip_info;
    TRACE( ( 1, "Inside dialupHandler" ) );
	switch ( responseCode )
    {
		case ED_OK_GPRS_SESSION_SET://GPRS session is set.
			TRACE( ( 1, "Inside ED_OK_GPRS_SESSION_SET" ) );
			ed_DialupGetIpInformations(&ip_info); //retrieve ip informations (retrieved as u32).
			adl_atSendResponse(ADL_AT_RSP,"\r\nLocal ip is ");
			dotted_notation(ip_info.LocalIP);//Print the ip information in dotted format
			adl_atSendResponse(ADL_AT_UNS,"\r\nSending File\r\n");
		ed_FTPGetConfig(&FTPParams);
		TRACE((1,"pw"));
		wm_strcpy(FTPParams.FtpPw,"<enter ftp password>");
		TRACE((1,"un"));
		wm_strcpy(FTPParams.FtpUn,"<eneter ftp username>");
		TRACE((1,"serv"));
		wm_strcpy(FTPParams.FtpServ,"<enter your server address>");
		TRACE((1,"SetConfig"));
		RetS8=ed_FTPSetConfig(&FTPParams);
		wm_sprintf(Temp,"%d",RetS8);
		TRACE((1,Temp));
		ed_FTPPutFileGetConfig(&FTPPutFileParams);
		TRACE((1,"filename"));
		wm_strcpy(FTPPutFileParams.FtpPutFilename,"walter.txt");
		TRACE((1,"path"));
		wm_strcpy(FTPPutFileParams.FtpPutPath,".");
		TRACE((1,"FTPFileSetConfig"));
		RetS8=ed_FTPPutFileSetConfig(&FTPPutFileParams);
		wm_sprintf(Temp,"%d",RetS8);
		TRACE((1,Temp));
		ed_FTPPut(FTPPutRspHandler,FTPPutDataHandler);
			break;
		case ED_INFO_CONNECT:
			TRACE( ( 1, "Inside ED_INFO_CONNECT" ) );
			break;
		case ED_OK_PPP:
			TRACE( ( 1, "Inside ED_OK_PPP" ) );
			ed_DialupGetIpInformations(&ip_info);
			adl_atSendResponse(ADL_AT_UNS,"\r\nLocal ip is ");
			dotted_notation(ip_info.LocalIP);
			break;
		case ED_OK_ON_HOOK:
			TRACE( ( 1, "Dial up connection closed" ) );
			adl_atSendResponse( ADL_AT_UNS, "\r\nDial up connection closed" );
			break;
		case ED_ERR_GPRS_ABORTED:
			TRACE((1,"ED_ERR_GPRS_ABORTED"));
			adl_atSendResponse(ADL_AT_UNS,"\r\nInternal GPRS error.Please check your APN parameters");
			break;
		default:
			TRACE((1,"default or error received in gprsHandler: responseCode - %d", responseCode));
			adl_atSendResponse( ADL_AT_UNS, "\r\nerror received in dial up connection start" );
			break;
	}
}

void timerHandler(u8 ID)
{
	s8 returnCode;
TRACE( ( 1, "Inside timerHandler" ) );
	returnCode = ed_DialupConnectionStart(dialupHandler );
	if(returnCode == 0)
	{
		TRACE((1,"ed_DialupConnectionStart success returnCode = %d",returnCode));
		adl_atSendResponse(ADL_AT_UNS,"\r\nTrying to retrieve ip information.Please wait until local ip is received...\r\n");
	}
	else
	{
		adl_atSendResponse( ADL_AT_UNS, "ed_DialupConnectionStart failed" );
		TRACE((1,"ed_DialupConnectionStart failed returnCode = %d",returnCode));
	}
}

void GPRSWait( u8 ID)
{
	s8 returnCode;
	TRACE( ( 1, "Inside GPRSWait" ) );
	wm_strcpy( APNParams.ApnUn,"");
	wm_strcpy( APNParams.ApnPw,"");
	wm_strcpy( APNParams.ApnServ,"internet");
	APNParams.Cid=1;
	APNParams.Mode=1;
	returnCode = ed_GprsSetConfig( &APNParams );
    if (returnCode == 0)
    {
		adl_tmrSubscribe(FALSE, 10, ADL_TMR_TYPE_100MS,timerHandler);
	}
	else
	{
		TRACE((1,"ed_GprsSetConfig failed returnCode = %d",returnCode));
	}
}

bool AttRspHandler(adl_atResponse_t *params)
{
	TRACE( ( 1, "Inside AttRspHandler" ) );
	//if an OK is received as response to AT+CGATT=1 command then set GPRS settings.
	if( !wm_strncmp( params->StrData, "\r\nOK", 4 ) )
	{
	//Ready
	adl_tmrSubscribe(FALSE,2,ADL_TMR_TYPE_TICK,GPRSWait);//Give modem time to process CGATT=1	
	}
		//if an OK is not received then create AT+CGATT=1 again.
	else
	{
		adl_atCmdCreate( "AT+CGATT=1", FALSE, AttRspHandler, "*", NULL );
	}
	return TRUE;
}

void SetupHandler(u8 ID)
{
	TRACE( ( 1, "Inside SetupHandler" ) );
	adl_atCmdCreate("AT+CGATT=1",FALSE,AttRspHandler,"*",NULL);
}

void simeventHandler(u8 Event)
{
	switch(Event)
	{
case ADL_SIM_EVENT_REMOVED:
break;
case ADL_SIM_EVENT_INSERTED:
break;
case ADL_SIM_EVENT_FULL_INIT:
break;
case ADL_SIM_EVENT_PIN_ERROR:
break;
case ADL_SIM_EVENT_PIN_OK:
break;
case ADL_SIM_EVENT_PIN_WAIT:
		break;
	case ADL_SIM_EVENT_PIN_NO_ATTEMPT:
		break;
	}
}

void adl_main ( adl_InitType_e InitType )
{
	ascii MyCmd[10];
    TRACE (( 1, "Inside adl_main" ));
    ed_Init();
	adl_atSendResponse(ADL_AT_UNS,"App Starting Please Wait 10 Seconds");
	adl_simSubscribe(simeventHandler,NULL);
	adl_tmrSubscribe(FALSE,100,ADL_TMR_TYPE_100MS,SetupHandler);
	adl_atCmdCreate("AT+CGCLASS=\"B\"",TRUE,NULL,NULL);
	Cell_Handle= adl_adSubscribe(1,ADL_AD_SIZE_UNDEF);
		if (Cell_Handle>=0)
		{
			TRACE(( 1,"Cell succesfully subscribed"));
		}
		else
		{
			TRACE((1,"Can do write to cell"));
		}
	if (InitType = ADL_INIT_DOWNLOAD_SUCCESS)
	{
		adl_adDelete(Cell_Handle);
	}
}

/*
App Will First Upload A File To FTP Server and 
then Download the Hallo_World.wpb.dwl from the FTP server.
On Completion It will Install It 
Reset 
and Run The New App
To Do In App To Be downloaded: Delete App on startup 
How?
Ans:Init Type will return "ADL_INIT_DOWNLOAD_SUCCESS" in main
(As shown In Main)(Not tested yet,but works in principle)
*/

#4

Hi Everybody
i have created a new DOTA application using the WIP stack
You can fild it at http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=1330