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({
hostName:'example.com',
port:21,
mode:Titanium.Network.READ_WRITE_MODE
});
controlSocket.addEventListener('read', function(e) {
Titanium.API.info("Control Read " + e.data + "From " +e.from + " Source " +e.source);
controlSocket.connect();
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?
Thanks
3 Answers
-
Accepted Answer
Michael,
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.
-
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 ?
-
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.
Thanks