Write to FTP

Hello all,

I have an aplication that has to write some values in a file to a ftp server. My code is:

ftpCnxCh = wip_FTPCreateOpts(FTP_STR_HOSTNAME, FTPCnxHandler, NULL,
		WIP_COPT_USER, FTP_STR_USERNAME, WIP_COPT_PASSWORD,
		FTP_STR_PASSWORD, WIP_COPT_PASSIVE, FTP_MODE, WIP_COPT_TYPE,
		FTP_TYPE, WIP_COPT_PEER_PORT, FTP_PORT, WIP_COPT_END);
void FTPCnxHandler(wip_event_t *ev, void *ctx)
    {
    switch (ev->kind)
	{
    case WIP_CEV_OPEN:
	{
	TRACE((1,"ftp:WIP_CEV_OPEN"));
	//ftpDataCh = wip_getFileOpts(ftpCnxCh, FTP_FILENAME, ftpDataHandler,
	//	NULL, WIP_COPT_END);
	adl_tmrSubscribe(TRUE, 100, ADL_TMR_TYPE_100MS, WriteToFtp);
	ftpDataCh = wip_putFile(ftpCnxCh, Date, ftpDataHandler, NULL );
	if (!ftpDataCh)
	    {
	    TRACE((1, "Can't create data channel" ));
	    return;
	    }
	}
	break;
    case WIP_CEV_PEER_CLOSE:
	TRACE((1,"WIP_CEV_PEER_CLOSE"));
	break;
    case WIP_CEV_ERROR:
	TRACE((1,"Not Connected to FTP"));
	break;
    case WIP_CEV_LAST:
	break;
    case WIP_CEV_READ:

    case WIP_CEV_DONE:
	break;
    case WIP_CEV_PING:
	break;
	}
    }
void ftpDataHandler(wip_event_t *ev, void *ctx)
    {
    switch (ev->kind)
	{
    case WIP_CEV_OPEN:
	TRACE((1,"ftpDataHandler: WIP_CEV_OPEN"));
	break;
    case WIP_CEV_READ:
	{
	u8 buf[256];
	wm_memset(buf, 0, 256);
	TRACE((1,"ftpDataHandler: WIP_CEV_READ"));
	while (wip_read(ftpDataCh, buf, 256) > 0)
	    {
	    TRACE((1,(char*)buf));
	    }
	}
	break;
    case WIP_CEV_WRITE:
	TRACE((1,"ftpDataHandler: WIP_CEV_WRITE"));
	break;
    case WIP_CEV_PEER_CLOSE:
	TRACE((1,"ftpDataHandler: WIP_CEV_PEER_CLOSE"));
	wip_close(ftpDataCh);
	wip_close(ftpCnxCh);
	break;
    case WIP_CEV_ERROR:
	TRACE((1,"ftpDataHandler: WIP_CEV_ERROR"));
	break;
    case WIP_CEV_PING:
	break;
    case WIP_CEV_DONE:
	break;
	}
    }
   wip_write(ftpDataCh, "This is a test. Testing", 23);
		    wip_write(ftpDataCh, "Nothing but testing", 19);
		    wip_close(ftpDataCh);

My question is how can I append to the file that it has already written? I have to say that the file will be very big so the solution with reading the file, adding at the end the new data and uploading again won’t help me.

Hiya,

Don’t call wip_close() until you have finished uploading…

Ciao, Dave

Thanks for you reply. I know that. But let’s say that i have to restart the modem. After that i want to add lines in the same file. If i do that it will overwrite the existing content. I hope you understand me.

Hiya,

You need to deal with FTP_RESUME in your server.

Have a look at the wip_putFileOpts() function (section 8.10) - there are some options there that will let you either append data to the end of the file, or restart the transfer after the n’th byte.

These might help you enable appending to a large file.

ciao, Dave