FTP close


#1

I am using Q24plus,

I am transferring file from modem to server using wip_putfile() and wip_write().

After transferring file if i use wip_close() and wip_bearerstop() i am getting WIP_CEV_ERROR and module restrats.

bearer_hdlr()
{
ftp_WipHandle = wip_FTPCreateOpts( ftp_address, ftp_SessionHandler_ls_tp, NULL, WIP_COPT_USER, ftp_usrname, WIP_COPT_PASSWORD, ftp_passwd, WIP_COPT_PEER_PORT, 21, WIP_COPT_END); 
}

ftp_sessionhandler()
{
ftp_WipDataHandle=wip_putFile(ftp_WipHandle,ftp_filename,ftp_DataHandler_ls_tp,NULL);
}

ftp_DataHandler_ls_tp()
{
wip_write( wip_channel, &recv_data_buf[ntimes], send_buff_size);
closeftpconnection()
}

closeftpconnection()
{
wip_close( ftp_WipHandle);
wip_bearerStop(wip_bearer);
}

How to close safely the ftp connection after successfully transferring the full file?

Please give suggestions.


#2
bearer_hdlr()
{
	ftp_WipHandle = wip_FTPCreateOpts( ftp_address, ftp_sessionhandler, NULL, WIP_COPT_USER, ftp_usrname, WIP_COPT_PASSWORD, ftp_passwd, WIP_COPT_PEER_PORT, 21, WIP_COPT_END);
}

ftp_sessionhandler(wip_event_t *ev, void *ctx)
{
	switch( ev->kind) {
	  case WIP_CEV_OPEN:
	  {
		  ftp_WipDataHandle=wip_putFile(ftp_WipHandle,ftp_filename,ftp_DataHandler_ls_tp,NULL);
		  break;
	  }
	  case WIP_CEV_ERROR:
		  wip_close( ev->channel);
		  wip_bearerStop(wip_bearer);
		  break;
	  case WIP_CEV_DONE:
		  wip_close(ev->channel);	// file transfer completed. close the control channel
		  wip_bearerStop(wip_bearer);
		  break;
	  case WIP_CEV_PEER_CLOSE:
	  {
	  	//Ftp server closed the channel.
	  	wip_close(ev->channel);
	  	wip_bearerStop(wip_bearer);
	  	break;
	  }
	  default:		  
		  break;
	  }
}

ftp_DataHandler_ls_tp( wip_event_t *ev, void *ctx)
{
	
	switch (ev->kind)
	{
		case WIP_CEV_OPEN:
			
			break;

		case WIP_CEV_READ:
			
			break;

		case WIP_CEV_WRITE:
				//f_enterFS();
				if (//no more data to send)
				{
					sRet = wip_close(ev->channel);
				}
				else
				{
					// ATTENTION: if your buffer is big, you have to send it in chunks
					wip_write(ev->channel, &recv_data_buf[ntimes], send_buff_size);
					break;
				}

			break;

		case WIP_CEV_DONE:
			{

				sRet = wip_close(ev->channel); // file transfer completed. close the data channel
			}
			break;

		case WIP_CEV_PEER_CLOSE:
			sRet = wip_close(ev->channel);	
			break;

		case WIP_CEV_ERROR:
		{
			// error handling
			break;
		}
		default:
			break;
	}
}

#3

Thanks Shekib.

I got the solution from WIP samples given in OpenAT suite.

it is working after modified as below
wip_close( ftp_WipDataHandle);
wip_close(ftp_WipHandle );

because ftp_WipDataHandle=wip_putFile(ftp_WipHandle,ftp_filename,ftp_DataHandler_ls_tp,NULL) will use tcp/ip channel to transfer file so we have to close first ftp connection and then close ev->channel

Have you checked because in my case giving wip_close(ev->channel) throws WIP_CEV_ERROR in ftp session handler?

wip_close( ftp_WipDataHandle) and wip_close(ftp_WipHandle ) working OK without restart