Flex FTP and socket error #2031
Copy link to clipboard
Copied
Hi to all!
I'm trying to develop a FTP client in Flex/Air with socket (...whatelse !?!?)
I can connect to the FTP server and authenticate. Then I switch to passive mode sending the "PASV" ftp command.
In response i receive the data port on which I will (...well...actually....on which I would like to....) transfer the files. And here comew the trouble.
I create a new socket wich attempts to connect on the port the server told me, it stands still for some moments and give me the socket error #2031.
Below the complete error (URL's IP replaced with 'xx.xx.xx.xx'):
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error URL: xx.xx.xx.xx" errorID=2031]
I've tried to google around but i didn't find anything useful more than Adobe Flex Socket reference (which doesn't even talk about #2031 error )
I've also tried to perform FTP task with the maliboo FTP lib but it behaves the same as mentioned before.
Any ideas,suggestions or solutions?
Thanks in advance guys for the attention!
Best regards!
Luca
P.S. :
Below the code I've used:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" initialize="init()">
<mx:Script>
<![CDATA[
private var sCommand:Socket
private var sData:Socket
private function init():void{
sCommand=new Socket("xx.xx.xx.xx",21);
sCommand.addEventListener(ProgressEvent.SOCKET_DATA,commandResponse)
sCommand.addEventListener(IOErrorEvent.IO_ERROR, commandError);
sCommand.writeUTFBytes("USER xxxxxx\n");
sCommand.flush();
sCommand.writeUTFBytes("PASS xxxxxxx\n");
sCommand.flush();
sCommand.writeUTFBytes("CWD /mydirectory/\n");
sCommand.flush();
sCommand.writeUTFBytes("PASV\n");
sCommand.flush();
}
private function commandResponse(e:ProgressEvent):void{
var command_resp:String=sCommand.readUTFBytes(sCommand.bytesAvailable)
if(command_resp.indexOf("227")>-1){
var temp:String = command_resp.substring(command_resp.indexOf("(")+1,command_resp.indexOf(")"));
var data_channel_temp:Array = temp.split(",");
var data_channel_ip:String=data_channel_temp.slice(0,4).join('.')
var data_channel_port:int=parseInt(data_channel_temp[4])*256+parseInt(data_channel_temp[5])
trace(data_channel_ip+" "+data_channel_port)
sData=new Socket(data_channel_ip,data_channel_port) //here it starts to stand still and after a while it crash with error #2031
sData.addEventListener(ProgressEvent.SOCKET_DATA,dataResponse)
sData.addEventListener(IOErrorEvent.IO_ERROR, dataError);
}
trace("command "+command_resp)
}
private function commandError(e:IOErrorEvent):void{
trace("command -> "+e.text)
}
private function dataResponse(e:ProgressEvent):void{
trace('data '+e)
}
private function dataError(e:IOErrorEvent):void{
trace('data error ' +e)
}
]]>
</mx:Script>
</mx:WindowedApplication>
Copy link to clipboard
Copied
How many different FTP servers have you used to try out this? for me it seems problem in the FTP server side..
Copy link to clipboard
Copied
First, thanks for your reply!
I've first tried on the main hosting platform we use and doesn't work.
This morning I've also tried on another low-cost hosting platofrm and it works quite well (I can get to make the data connection in passive mode and retrieve the file list).
The weird thing is that since our main hosting platform has changed the server the flex ftp doesn't work anymoe. Before, all worked well.
If is a problem of FTP server which colud be the cause?
Could be due to a wrong configuration?Some firewall?
Another strange thing is that other FTP client such Fetch or FileZilla connects well without any problem.Maybe flex socket lack of something?
Below some information about the server (this is the FileZilla log):
220---------- Welcome to Pure-FTPd [TLS] ----------
[...]
SYST
215 UNIX Type: L8
FEAT
211-Extensions supported:
EPRT
IDLE
MDTM
SIZE
REST STREAM
MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
MLSD
ESTP
PASV
EPSV
SPSV
ESTA
AUTH TLS
PBSZ
PROT
Let me Know!!!
Best regards!
Copy link to clipboard
Copied
fetch feature sets from both FTP servers and compare them to eliminate the possible difference.
also please mark helpful posts to ease up others to find same looking solutions faster, thanks.
Copy link to clipboard
Copied
Well, i've tried to figure out the differences but the 2 server give different response (one is more verbose than the other) so i cannot see which differences occur between the two server. The only thing that i found is that both server run on ProFTPd
I cannot understand why the socket gets to connect and authenticate, but when it's time to open the passive connection the sockets (on which the date should flow) fails with error#2031.
Does AIR have some limitation about the port range which socket can connect?
Thansk so much for the help!
Copy link to clipboard
Copied
Hi to all!!!
After some painful hours of research I've achieved what has changed on the server.
The main difference between the old server and the new one is that the previous had a dedicated ip address for each domain while the new one is a shared ip hosting solution.
Do you think this could affect the ftp library to crash or conduce to throw the famous #2031 socket error?
As said previously the weird thing is that other ftp client such filezilla or fetch work fine.
Thanks in advance for tha patience!!!
Best regards!
Copy link to clipboard
Copied
I am facing the exact same problem. I am not able to close the data connection. Were you able to solve this problem? I am using filezila server. I need a 226 response from the server to indicate that the transfer is complete. If you have any inputs from your side maybe we can break our heads together.
Copy link to clipboard
Copied
Unfortunately I wasn't able to solve the problem . I've also opened several ticket with my hosting company, let them change the ftp server software (switched between pureFTP and proFTPd) but no way!
One thing that I've noticed is that things started to getting worse when the hosting switched from a dedicated ip system to a shared ip system. While I was setting up the ftp application I tried to connect to another hosting provider that use shared ip system an it crashes as well.
My problem stands when I try to switch to passive mode, it stands still for a while and it crashes with the nice socket error #2031 ( very well documented ... ... just kidding).
In the meanwhile I find the solution I continue banging my head on the desk!!
Hope to find out a solution!
Best regards!
Copy link to clipboard
Copied
well i am trying to use wireshark to see what TCP/IP packets are being sent and
what all is happening. I would recommend the same to you as well. Sleepless nights ahead . I have also asked my seniors who have developed flex.
Copy link to clipboard
Copied
Further, I am not so sure if the trouble is with the server. I have seen lots of people crying their hearts out
with binary sockets.
Copy link to clipboard
Copied
Could you do one thing for me? Create logs from your application to figure out as to which particular call
at the data connection is causing this IO Error.. is it the closing of the connection or the creation of a new connection. Maybe even the IP of the server and the port of the data connection be a part of the logs. This can help us to narrow down error 2031 on ourselves.
Copy link to clipboard
Copied
Partner in crime
read this
http://tech.groups.yahoo.com/group/flexcoders/messages/72018?threaded=1&m=e&var=1&tidx=1
it simply says that there is a certain limitation with Flex sockets and to fix that some modification to the application protocol is required.
Copy link to clipboard
Copied
Thanks, I've just read the tread. Pretty intersting.
They say a lot about transfering huge amoung of data, but our problem reside in establishing the connection.
For creating the application I used the FlexFTP library of Maliboo but it crash as well my own plain code.
I read over the internet the the socket class lacks of many functionality, maybe they gotta improve a little bit more.
I would like to try with flex4
ASAP I'll post the wireshark log. I did it in the past but I didn't save it!!!
Good bye!!
Keep on fighting against socket!!!
Have a nice day!
Luke
Copy link to clipboard
Copied
I had the exact same issue and same symptoms. However I was lucky that I had control over the hosting server and firewall server. I got it working by:
- Login to the hosting server and modify pureFTP to only open ports from range 45000-50000
- Login to the firewall server that's protecting the hosting server and added a allow port range 45000-50000 from any source
- Run the AS FTP client and it worked nicely!
Hope that helps you. I also tried Wireshark, but the responses were very similar between filezilla and the Flash FTP client. Still don't know how filezilla does it, but the above worked for me 100% of the time.
Good luck in solving your issue!
Copy link to clipboard
Copied
Luke,
I am able to connect to my FTP server and my code is very similar to yours. Could you try once by creating a local FTP server? This way we can be sure that it is no network/firewall issue.
