Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

TCPIP Sockets to do FTP

I have seen some questions along this path but was hoping to get a concrete answer. I am trying to do FTP communication using the TCPSocket. So what I am doing:

var controlSocket = Ti.Network.createTCPSocket({

controlSocket.addEventListener('read', function(e) {
Titanium.API.info("Control Read " + e.data + "From " +e.from + " Source " +e.source);


Alright, so from my output from e.data I can see that I connect okay, I get back the message

"Control Read 220 Microsoft FTP Service From 8 Source [object TiNetworkTCPSocket]"

So it seems like it connects. However I don't get any other information after that. I expect to get something like "Username Required:" or anything, and if I do any controlSocket.write("TEST") commands I don't get a response at all.

When I do this FTP from my terminal it works as expected and prompts for username.

Has anyone successfully got a socket FTP connection working through Titanium? What am I doing wrong?


— asked July 31st 2010 by Michael Craig
  • ftp
  • socket
  • tcp

3 Answers

  • Accepted Answer


    You will have FTP login issues with the current 1.4.0 release, because the TCPSocket also sends a terminating null character when sending strings.

    This has already been resolved in one of the recent commits, so you could try installing one of the continuous builds from GitHub before testing your FTP code. The TCPSocket now has a stripTerminator property which you'll need to set to true before you connect to your FTP server.

    I created a quick & dirty example which successfully connects and logs in to my FTP server: app.js.

    — answered August 1st 2010 by Goran Skledar
    • There's also a shorter answer to what you were doing wrong: you forgot to add the CR+LF after sending a command to the FTP server :)

      — commented August 1st 2010 by Goran Skledar
    • Hi Goran, I know it's been 3 years now, but can you provide some code sample where one is able to send an image to FTP folder? I am able to login into the FTP folder using TCPSocket and all, but for the past 5 days, for the life of me, I can't send images. Any help would be highly appreciated.


      — commented December 12th 2013 by Paulo Dichone
    • Hi Paulo,

      Can you please provide me an example of how to have ftp connection..

      — commented June 10th 2014 by Aparna M
  • Hi, I am trying to retrieve the list of a directory on a ftp server but when i do that i have an error:

    425 Unable to build data connection: Invalid argument

    I tried to put the server on passive mode, and then i have no error but nothing is received

    Have you an example of working system ?

    — answered July 27th 2012 by Nidal Chabab
  • Hi there,

    My issue is that I can't log in to the servers. All goes well, but then I get a " 331 User myservernam OK. Password required" in the console. Any ideas why I am getting this? I have checked my password and is correct.


    — answered December 9th 2013 by Paulo Dichone
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.