Hi Dave,
Thanks for your interest here. Following is the code. I am relatively new here (in terms of amount of time spent) and I am sorry I am not aware what you mean by code tagging. Just a gentle reminder that this code works fine with three network operators but doesn’t work with Vodafone and Reliance. I am in correspondence with these operators but no solution or suggestion has been given by them as yet.
void fileopr (){ // basic function to initiate ftp upload.
uplen = 0;
senddebug ("\r\nLarge file operation", 'M', 5);
if ((clienttest.schnl = wip_FTPCreateOpts (ftpserver, ftpupstart, NULL, WIP_COPT_USER, ftplogin, WIP_COPT_PASSWORD, ftppass,
WIP_COPT_PEER_PORT, atoi (ftpprm1), // ftpprm1 stores port no. (set to 21)
WIP_COPT_PASSIVE, (ftpstate == 'A') ? FALSE:TRUE, // ftpstate stores state (set to active)
WIP_COPT_END)) == 0) senddebug ("\r\nCannot create FTP session channel", 'M', 5);
else senddebug ("\r\nFTP session channel created", 'M', 5);
}
void ftpupstart (wip_event_t *ev, void *ctx){ // used for ftp upload
switch (ev->kind){
case WIP_CEV_OPEN:
clienttest.dchnl = wip_putFileOpts (clienttest.schnl, filetoupload, updata, NULL, WIP_COPT_END);
senddebug ("\r\nFTP data channel created", 'M', 5); // filetoupload has been previously defined along with path on ftp server
break;
case WIP_CEV_PEER_CLOSE:
closechannels ();
break;
case WIP_CEV_DONE:
closechannels ();
break;
case WIP_CEV_ERROR:
closechannels ();
break;
default:
break;
}
}
void updata (wip_event_t *ev, void *ctx){ // used for actually write (and in general, monitor) during ftp
char upbuf[100];
int prelen;
switch (ev->kind){
case WIP_CEV_WRITE:
if (uplen < flen){ // flen is size of data in dotabuf
if ((prelen = wip_write (clienttest.dchnl, dotabuf+uplen, flen)) < 0) return; // dotabuf holds data to be uploaded to file
uplen += prelen; // increment uplen by prelen
sprintf (upbuf, "\r\nNo. of bytes written: %5d\r\n", prelen);
senddebug (upbuf, 'M', 5);
}
if (uplen >= flen) wip_shutdown (clienttest.dchnl, FALSE, TRUE);
break;
case WIP_CEV_ERROR:
closechannels ();
break;
case WIP_CEV_PEER_CLOSE:
closechannels ();
break;
case WIP_CEV_DONE:
closechannels ();
break;
default:
break;
}
}
void closechannels (){ // used for ftp or http
wip_close (clienttest.dchnl);
wip_close (clienttest.schnl);
senddebug ("\r\nFTP / HTTP file operation: Over", 'M', 5);
}
void senddebug (char *strn, char dest, char level){ // debug levels to be added afterwards. presently, debuglevel is set 5
if (dest == 'M' && level >= debuglevel) adl_atSendResponse (ADL_AT_RSP, strn); // destination M means serial port 1
}
Regards.
Sanjeev