# Cannot run FTP as a Task

**URL:** <https://forum.sierrawireless.com/t/cannot-run-ftp-as-a-task/5494>\
**Category:** Open AT\
**Created:** [March 2, 2012, 8:18pm UTC](https://forum.sierrawireless.com/t/cannot-run-ftp-as-a-task/5494 "2012-03-02T20:18:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bakalis](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@bakalis](https://forum.sierrawireless.com/u/bakalis)\
**Post date:** [March 2, 2012, 8:18pm UTC](https://forum.sierrawireless.com/t/cannot-run-ftp-as-a-task/5494/1 "2012-03-02T20:18:12Z")

</div>

I have been attempting to use the message service to launch an FTP task within a FXT009 modem. The bearer is successfully opened during initialization of the main task which has the highest priority. The following lists the task declaration table.

```auto
const adl_InitTasks_t adl_InitTasks [] = {
    { main_task, 3072, "main", 5 },
    { uart_task, 3072, "uart", 4 },
    { timer_task, 3072, "timer", 3 },
    { FTP_task, 3072, "FTP", 2 },
    { FLASH_task, 3072, "FLASH", 1 },
    { 0, 0, 0, 0 } }
```

The FTP\_task initializes the message service as follows:

```auto
S32 FTP_task (void)
{ s32 s32Return;
  static adl_msgFilter_t msgFilter = { 0, 0, ADL_MSG_ID_COMP_EQUAL, ADL_CTX_ALL };
  s32Return = adl_msgSubscribe (&msgFilter, FTP_handler);
}
```

Then a message is sent by another task to send a file via FTP by issuing the following:

```auto
void FTP_handler (u32 MsgIdentifier, adl_ctxID_e ctxSource, u32 Length, void * incomingData)
{
dst_ftp_cx = wip_FTPCreateOpts (FTP_Server,
	FTP_Session_Handler, NULL,
	WIP_COPT_USER, FTP_User,
	WIP_COPT_PASSWORD,FTP_Password
	WIP_COPT_PASSIVE, DST_ISPASSIVE,
	WIP_COPT_PEER_PORT, (u16)atoi(FTP_Port),
	WIP_COPT_END );
}
```

There are no messaging errors detected and the wip\_FTPCreateOpts is executed. Then depending on the server address, the wip\_FTPCreateOpts either returns a channel or a null (error). In the case when channel address is returned, there is no further FTP activity, i.e. no WIP\_CIV events occur and the FTP seems dead.

When I rewrite the code to not use messaging and call the FTP\_handler function directly, everything works fine. Any suggestion as to how to launch an FTP as a task rather than a function call would be most appreciated.

---

<div class="post-metadata">

**Author:** ![Rex\_alex](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Rex\_alex](https://forum.sierrawireless.com/u/Rex_alex)\
**Post date:** [March 5, 2012, 11:56am UTC](https://forum.sierrawireless.com/t/cannot-run-ftp-as-a-task/5494/2 "2012-03-05T11:56:42Z")

</div>

Hi,

Please note as per the doc “WIP\_Open\_AT\_IP\_Connectivity\_Development\_Guide.pdf”, “wip\_netinit”  
API has to be called from each task to reserve the associated execution context for each WIPlib Plug-  
In operation. Please confirm the same. Also check if the FTP creation was done only after the WIP\_BEV\_IP\_CONNECTED event was received in the bearer handler.

---

<div class="post-metadata">

**Author:** ![tomridl](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/tomridl/32/2704_2.png) [@tomridl](https://forum.sierrawireless.com/u/tomridl)\
**Post date:** [March 5, 2012, 12:25pm UTC](https://forum.sierrawireless.com/t/cannot-run-ftp-as-a-task/5494/3 "2012-03-05T12:25:34Z")

</div>

Try this in your FTP start function (as Rex\_Alex said, only after you are sure your GPRS bearer has started correctly):

```auto
const ascii * FTP_STR_HOSTNAME = "www.yourftpaddress.com";

static void pfk_FTPStart (void)
{
    const ascii * FTP_STR_USERNAME = "test123";
    const ascii * FTP_STR_PASSWORD = "test123";

    TRACE((FTP_TRACE_LEVEL1, FTP_STR_USERNAME));
    TRACE((FTP_TRACE_LEVEL1, FTP_STR_PASSWORD));

    if (wip_netInit() == 0)
    {
        FtpCnxCh = wip_FTPCreateOpts((ascii *) FTP_STR_HOSTNAME, pfk_ftpCnxHandler, NULL, WIP_COPT_USER, FTP_STR_USERNAME,
                WIP_COPT_PASSWORD, FTP_STR_PASSWORD, WIP_COPT_PASSIVE, TRUE, WIP_COPT_TYPE, (ascii) FTP_TYPE,
                WIP_COPT_PEER_PORT, 21, WIP_COPT_END);

        if (FtpCnxCh != NULL)
        {
            TRACE((FTP_TRACE_LEVEL1,"[pfk_FTPStart] FTP control channel created: %d", FtpCnxCh));
        }
        else
        {
            TRACE((FTP_TRACE_LEVEL1,"[pfk_FTPStart] FTP channel cannot be created: %d", FtpCnxCh));
            pfk_ftpError();
        }
    }
    else
    {
        TRACE((FTP_TRACE_LEVEL1, "[pfk_FTPStart] Could not re-init WIP"));
    }
}
```
