PDA

View Full Version : Error #2048: Security sandbox violation - To FTP


moshiur
08-06-2009, 05:06 PM
Hi,

I am trying to connect to FTP and but keep getting Error 2048.
The FTP software and my Flex code lives on the server.

I'm using Flex 3.2 & Flash player 10.

Error #2048: Security sandbox violation: http://mySubDomain1.Domain.com/bin-debug/ftp.swf cannot load data from mySubDomain2.Domain.com:21.

I have cross domain on my server root directory (mySubDomain2.Domain.com - inetpub/wwwroot)
and application directory (mySubDomain1 - inetpub/wwwroot/myProject/html)


SWF File: http://mySubDomain1.Domain.com/bin-debug/ftp.html
Cross Domain: http://mySubDomain2.Domain.com/crossdomain.xml

Here is my Code:

------------ Start Code------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" initialize="init()">


<mx:Script>
<![CDATA[

public var ftp_response:String;
public var data_response:String;
public var data_channel_ip:String;
public var data_channel_port:int;
public var data_channel:Socket;
public var s:Socket;


public function init():void
{
Security.allowDomain("*");
Security.loadPolicyFile("http://mySubDomain2.Domain.com/crossdomain.xml");

s = new Socket("mySubDomain2.Domain.com",21);
s.addEventListener(ProgressEvent.SOCKET_DATA, receiveReply);
s.addEventListener(IOErrorEvent.IO_ERROR, showError);
s.addEventListener(SecurityErrorEvent.SECURITY_ERR OR, showSecError);
s.writeUTFBytes("USER xxxx\n");
s.flush();
s.writeUTFBytes("PASS xxxx");
s.flush();
s.writeUTFBytes("CWD /upload/\n");
s.flush();
s.writeUTFBytes("PASV\n");
s.flush();
}

public function receiveReply(e:ProgressEvent):void{
ftp_response = s.readUTFBytes(s.bytesAvailable);
if(ftp_response.indexOf('227')>-1){
//get the ip from the string response
var temp = ftp_response.substring(ftp_response.indexOf("(")+1,ftp_response.indexOf(")"));
var data_channel_temp = temp.split(",");
data_channel_ip = data_channel_temp.slice(0,4).join(".");
//calculate the port number from the last two digits - if this makes no sense, google FTP PROTOCOL - there are loads of guides that explain the server responses.
data_channel_port = parseInt(data_channel_temp[4])*256+int(data_channel_temp[5]);
//use the new IP to open a second socket - this will transmit the data. Your first socket will transmit any commands you issue and this new socket will transmit the data
data_channel = new Socket(data_channel_ip,data_channel_port);
data_channel.addEventListener(ProgressEvent.SOCKET _DATA, receiveData);
s.writeUTFBytes("LIST\n");
s.flush();
}
trace(ftp_response);
ta.text = ta.text + '\n' + ftp_response;
}
public function receiveData(e:ProgressEvent):void{
data_response = data_channel.readUTFBytes(data_channel.bytesAvaila ble);
trace(data_response);
ta.text = ta.text + '\n' + data_response;
}
public function showError(e:IOErrorEvent):void{
trace(e.text);
ta.text = ta.text + '\n' + e.text;
}
public function showSecError(e:SecurityErrorEvent):void{
trace(e.text);
ta.text = ta.text + '\n' + e.text;
}
]]>
</mx:Script>
<mx:Panel id="up" horizontalAlign="left" width="100%" height="100%">
<mx:Box width="100%" height="100%">
<mx:VBox >
<mx:Form width="449" height="284">

<mx:FormItem label="Events2:">
<mx:TextArea id="ta" width="260" height="98" />
</mx:FormItem>
</mx:Form>
</mx:VBox>
</mx:Box>
</mx:Panel>
</mx:Application>

------------ End Code------------

Crossdomian.xml

------------ Start Cross Domain Code------------
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all" />
<allow-access-from domain="*" to-ports="21" />
</cross-domain-policy>
------------ End Cross Domain Code------------


FULL ERROR CODE:

1) Flex error message trying to read crossdomain.xml
------------ Start Error Message ------------
[SWF] /bin-debug/ftp.swf - 914,871 bytes after decompression
Warning: [strict] Ignoring policy file at xmlsocket://mySubDomain2.Domain.com:21 due to incorrect syntax. See http://www.adobe.com/go/strict_policy_files to fix this problem.

*** Security Sandbox Violation ***
Connection to mySubDomain2.Domain.com:21 halted - not permitted from http://mySubDomain1.Domain.com/bin-debug/ftp.swf
Error: Request for resource at xmlsocket://mySubDomain2.Domain.com:21 by requestor from http://mySubDomain1.Domain.com/bin-debug/ftp.swf is denied due to lack of policy file permissions.
------------ End Error Message ------------


2) Log file from running SWF file.
------------ Start Log File------------
OK: Root-level SWF loaded: http://mySubDomain1.Domain.com/bin-debug/ftp.swf
OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://mySubDomain2.Domain.com:21 by requestor from http://mySubDomain1.Domain.com/bin-debug/ftp.swf
OK: Policy file accepted: http://mySubDomain2.Domain.com/crossdomain.xml
Warning: [strict] Ignoring policy file at xmlsocket://mySubDomain2.Domain.com:21 due to incorrect syntax. See http://www.adobe.com/go/strict_policy_files to fix this problem.
Error: Request for resource at xmlsocket://mySubDomain2.Domain.com:21 by requestor from http://mySubDomain1.Domain.com/bin-debug/ftp.swf is denied due to lack of policy file permissions.

------------ End Log File------------

When I use Firefox, I can see that crossdomain file is loading from http://mySubDomain2.Domain.com/crossdomain.xml, but still setting the same error.

I can connect fine using FileZilla or using web browser. No luck using flex.

HELP !!!!!!!!!!!!!!!

Sekhar
08-08-2009, 06:30 PM
Well, the error message says it's ignoring the policy file because of bad syntax.

moshiur
08-10-2009, 04:28 PM
Hi Sekhar,

If you look at my cross domain above, it doesn't have any bad syntex.

I also ran a different test with the same cross domain and it worked fine. But can't get he ftp working.

Test Code
public function initApp():void
{
Security.allowDomain( "mySubDomain2.Domain.com" );
Security.loadPolicyFile( "http://mySubDomain2.Domain.com/crossdomain.xml" );

var request:URLRequest =
new URLRequest( "http://mySubDomain2.Domain.com/crossdomain.xml" );
var loader:URLLoader = new URLLoader();
loader.load( request );

}


LOG FILE
OK: Root-level SWF loaded: http://mySubDomain1.Domain.com/bin-debug/mediaManager.swf
OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at http://mySubDomain2.Domain.com/crossdomain.xml by requestor from http://mySubDomain1.Domain.com/bin-debug/ftp.swf
OK: Policy file accepted: http://mySubDomain2.Domain.com/crossdomain.xml
OK: Request for resource at http://mySubDomain2.Domain.com/crossdomain.xml by requestor from http://mySubDomain1.Domain.com/bin-debug/ftp.swf is permitted due to policy file at http://mySubDomain2.Domain.com/crossdomain.xml

Anything else you can think of?