我有一個AS3腳本連接到FTP服務器和retrievevs文件/文件夾列表。當設備通過WiFi或LAN連接到互聯網 該腳本工作正常,但它不能登錄時,它通過手機的3G連接AS3 FTP套接字在3G網絡上失敗
這裏是我的代碼:
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.net.Socket;
import flash.events.IOErrorEvent;
import flash.errors.IOError;
//
var ftp_host:String="ftp.server.com";
var ftp_port:Number=21//or your ftp port;
var ftp_username:String="username";
var ftp_password:String="password";
var ftp_path:String="/";
var s,r;
var listOfFiles:Array;
//
readFromFTP()
function readFromFTP(e=null){
s = new Socket(ftp_host,ftp_port);
r = new Socket();
listOfFiles=new Array();
s.addEventListener(IOErrorEvent.IO_ERROR,onIOERR);
s.addEventListener(ProgressEvent.SOCKET_DATA, onReturnData);
s.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecERR);
r.addEventListener(ProgressEvent.SOCKET_DATA, onServData);
r.addEventListener(Event.CONNECT, onPasvConn);
r.addEventListener(IOErrorEvent.IO_ERROR,onIOERR);
r.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecERR);
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleGlobalErrors);
}
function onReturnData(evt:ProgressEvent)
{
var d = s.readUTFBytes(s.bytesAvailable);
trace(d);
text_txt.appendText(d);
if(d.indexOf("220 ")>-1){
text_txt.appendText("Username sent\n");
s.writeUTFBytes("USER "+ftp_username+"\n");
s.flush()
}
if(d.indexOf("331 ")>-1){
text_txt.appendText("Password sent\n");
s.writeUTFBytes("PASS "+ftp_password+"\n");
s.flush()
}
if (d.indexOf("230") > -1)
{
text_txt.appendText("PASV command sent\n");
s.writeUTFBytes("PASV \n");
s.flush();
}
var a = d.indexOf('227');
if (a > -1)
{
var st = d.indexOf("(",a);
var en = d.indexOf(")",a);
var str;
str = d.substring(st + 1,en);
var a2 = str.split(",");
var p1 = a2.pop();
var p2 = a2.pop();
var ip:String = a2.join(".");
var port:int=(p2*256)+(p1*1);
r.connect(ip, port);
}
if(d.indexOf("226 ")>-1){
text_txt.appendText("QUIT command sent\n");
s.writeUTFBytes("QUIT \n");
s.flush();
}
if(d.indexOf("221 ")>-1){
}
}
function onPasvConn(evt:Event):void
{
//trace("CONNECTED TO DATA PORT");
text_txt.appendText("CONNECTED TO DATA PORT\n");
s.writeUTFBytes("NLST "+ftp_path+"\n");
s.flush();
}
function onServData(evt:ProgressEvent):void
{
var d = r.readUTFBytes(r.bytesAvailable);
trace(d);
text_txt.appendText(d);
}
function onIOERR(evt:IOErrorEvent)
{
trace(evt.errorID+":"+evt.text);
text_txt.appendText(evt.errorID+":"+evt.text);
}
function onSecERR(evt){
text_txt.appendText("Security error\n");
}
function handleGlobalErrors(evt){
text_txt.appendText("Unhandeled Error\n");
}
嘗試端口10000,因爲根據10000個保留端口 –