473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

FTP socket fails on 3G ntwork

258 100+
Hi everyone
I have written an AS3 socket script to retreive data from a FTP server .
It works fine when the device is connected to WIFI.

The problem is that most of the times it fails on 3G network.

Expand|Select|Wrap|Line Numbers
  1. import flash.events.ProgressEvent;
  2. import flash.events.Event;
  3. import flash.net.Socket;
  4. import flash.events.IOErrorEvent;
  5. import flash.errors.IOError;
  6. //
  7. var ftp_host:String="ftp.myserver.com";
  8. var ftp_port:Number=21//or your ftp port;
  9. var ftp_username:String="username";
  10. var ftp_password:String="password";
  11. var ftp_path:String="/";
  12. var s,r;
  13. var listOfFiles:Array;
  14. //
  15.  
  16.  
  17. readFromFTP()
  18.  
  19. function readFromFTP(e=null){
  20.     s = new Socket(ftp_host,ftp_port);
  21.     r = new Socket();
  22.     listOfFiles=new Array();
  23.     s.addEventListener(IOErrorEvent.IO_ERROR,onIOERR);
  24.     s.addEventListener(ProgressEvent.SOCKET_DATA, onReturnData);
  25.     s.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecERR);
  26.     r.addEventListener(ProgressEvent.SOCKET_DATA, onServData);
  27.     r.addEventListener(Event.CONNECT, onPasvConn);
  28.     r.addEventListener(IOErrorEvent.IO_ERROR,onIOERR);
  29.     r.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecERR);
  30. }
  31.  
  32.  
  33. function onReturnData(evt:ProgressEvent)
  34. {
  35.     var d = s.readUTFBytes(s.bytesAvailable);
  36.     trace(d);
  37.     text_txt.appendText(d);
  38.     if(d.indexOf("220 ")>-1){
  39.        s.writeUTFBytes("USER "+ftp_username+"\n");
  40.        s.flush()
  41.     }
  42.     if(d.indexOf("331 ")>-1){
  43.        s.writeUTFBytes("PASS "+ftp_password+"\n");
  44.        s.flush()
  45.     }
  46.     if (d.indexOf("230") > -1)
  47.     {
  48.         s.writeUTFBytes("PASV \n");
  49.         s.flush();
  50.     }
  51.     var a = d.indexOf('227');
  52.     if (a > -1)
  53.     {
  54.         var st = d.indexOf("(",a);
  55.         var en = d.indexOf(")",a);
  56.         var str;
  57.         str = d.substring(st + 1,en);
  58.         var a2 = str.split(",");
  59.         var p1 = a2.pop();
  60.         var p2 = a2.pop();
  61.         var ip:String = a2.join(".");
  62.         var port:int=(p2*256)+(p1*1);      
  63.         r.connect(ip, port);
  64.     }
  65.     if(d.indexOf("226 ")>-1){
  66.         s.writeUTFBytes("QUIT \n");
  67.         s.flush();
  68.     }
  69.     if(d.indexOf("221 ")>-1){
  70.     }
  71. }
  72. function onPasvConn(evt:Event):void
  73. {
  74.     //trace("CONNECTED TO DATA PORT");
  75.     text_txt.appendText("CONNECTED TO DATA PORT\n");
  76.     s.writeUTFBytes("NLST "+ftp_path+"\n");
  77.     s.flush();
  78. }
  79. function onServData(evt:ProgressEvent):void
  80. {
  81.     var d = r.readUTFBytes(r.bytesAvailable);
  82.     trace(d);
  83.     text_txt.appendText(d);
  84. }
  85. function onIOERR(evt:IOErrorEvent)
  86. {
  87.     trace(evt.errorID+":"+evt.text);
  88.     text_txt.appendText(evt.errorID+":"+evt.text);
  89. }
  90.  
  91. function onSecERR(evt){
  92.     text_txt.appendText("Security error:"+evt.errorID+":"+evt.text);
  93. }
  94.  
  95.  
Jun 9 '12 #1
0 1891

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Billism | last post by:
My email client (I programmed) recently has stopped being able to send email with my XP machine. I have had 3 other friends test it and the same thing happens. The program has not changed, but...
33
by: n00m | last post by:
import socket, thread host, port = '192.168.0.3', 1434 s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.connect((host, 1433))...
2
by: Nans | last post by:
One basic ASP.NET database issue…. I have a c# app running on a iis6 on one win2k3 adv servermachine & database on other win2k server machine…(in the same domain) Using windows authentication in...
1
by: Mr. Beck | last post by:
Hello, Please Help..... I have been working with some tcp/ip socket communication within a C# program recently. Basicly, I have a program (myProblemProgram) that has a socket connected to...
5
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
10
by: cjard | last post by:
I have a client and server that enjoy the following simple dialogue: Client connects Client sends request Server sends response Client disconnects This is the way it must be. The response...
4
by: O.B. | last post by:
I have a socket configured as TCP and running as a listener. When I close socket, it doesn't always free up the port immediately. Even when no connections have been made to it. So when I open...
11
by: mthread | last post by:
Hi, I am planning to write a TCP/IP server. I would like to know if any socket library is available for c++ or I have to use the socket function calls in C.
2
by: Martin | last post by:
I have the following code being used in several of my PHP scripts (it's in an include file). It opens a socket connection to a process that's running on the same computer that IIS/PHP is running...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.