Sorry for the subject line sounding like an even nerdier Harry Potter title.
对不起,主题听起来像哈利波特的标题。
I'm trying to use AS3's Socket class to write a simple FTP program to export as an AIR app in Flex Builder 3. I'm using an FTP server on my local network to test the program. I can successfully connect to the server (the easy part) but I can't send any commands. I'm pretty sure that you have to use the ByteArray class to send these commands but there's some crucial piece of information that I'm missing apparently. Does anyone know how to do this? Thanks! Dave
我正在尝试使用AS3的Socket类编写一个简单的FTP程序,以便在Flex Builder 3中导出为AIR应用程序。我在本地网络上使用FTP服务器来测试程序。我可以成功连接到服务器(简单部分),但我无法发送任何命令。我很确定你必须使用ByteArray类来发送这些命令,但是我显然缺少一些重要的信息。有谁知道如何做到这一点?谢谢!戴夫
8 个解决方案
#1
3
The FTP protocol predates UTF encoding. Switch to ANSI/ASCII for better results. If you do opt for writeMultiByte instead of writeUTFBytes, be aware that it is buggy in linux. Here's one way around it.
FTP协议早于UTF编码。切换到ANSI / ASCII以获得更好的结果。如果你选择writeMultiByte而不是writeUTFBytes,请注意它在linux中是错误的。这是绕过它的一种方式。
There's another question here where the line ending turns out to be the culprit, so make sure that you get it right (as suggested above).
这里还有另一个问题,那里的行结尾是罪魁祸首,所以请确保你做对了(如上所述)。
As said before, if this is running from the web, all socket connections will require a crossdomain policy, but this is NOT file based over HTTP. Recent changes to the security rules mean that any socket based connection must first get a crossdomain from a policy server hosted on port 843 of the target host.
如前所述,如果这是从Web运行的,则所有套接字连接都需要跨域策略,但这不是基于HTTP的文件。最近对安全规则的更改意味着任何基于套接字的连接必须首先从目标主机的端口843上托管的策略服务器获取跨域。
Quoting from Adobe:
引用Adobe:
A SWF file may no longer make a socket connection to its own domain without a socket policy file. Prior to version 9,0,115,0, a SWF file was permitted to make socket connections to ports 1024 or greater in its own domain without a policy file.
如果没有套接字策略文件,SWF文件可能不再与其自己的域建立套接字连接。在版本9,0,115,0之前,允许SWF文件在没有策略文件的情况下在其自己的域中建立到1024或更大端口的套接字连接。
HTTP policy files may no longer be used to authorize socket connections. Prior to version 9,0,115,0, an HTTP policy file, served from the master location of /crossdomain.xml on port 80, could be used to authorize a socket connection to any port 1024 or greater on the same host.
HTTP策略文件可能不再用于授权套接字连接。在版本9,0,115,0之前,可以使用从端口80上的/crossdomain.xml的主位置提供的HTTP策略文件来授权到同一主机上的任何1024或更高端口的套接字连接。
Essentially, what this means is that you must be in control of the target FTP host, and install supplementary software on it to get this working.
从本质上讲,这意味着您必须控制目标FTP主机,并在其上安装补充软件才能使其正常工作。
#2
#3
1
I've been able to get an FTP client working in a browser, but it's buggy. I had to get a listener running on port 843 to server the policy file so that Flash would be allowed to connect and transfer data. Then, I had to figure out how FTP actually works:
我已经能够在浏览器中使用FTP客户端,但它有问题。我必须在端口843上运行一个侦听器来为策略文件提供服务,以便允许Flash连接和传输数据。然后,我必须弄清楚FTP实际上是如何工作的:
You have to open 2 sockets: a command socket and a data socket. The command socket is where you send your USER, PASS, CWD, and STOR commands. The data socket is where you write your ByteArray data to. Sending the PASV command will tell you what port your data socket must connect to.
您必须打开2个套接字:命令套接字和数据套接字。命令套接字是您发送USER,PASS,CWD和STOR命令的地方。数据套接字是您将ByteArray数据写入的位置。发送PASV命令将告诉您数据套接字必须连接到哪个端口。
Where it is buggy is on Mac, in both Safari and FF, when I call the "socket.close()" command, the server socket actually closes. On Windoze, it does not. This is a huge problem because the Event.CLOSE event is not fired until the SERVER closes the connection. This is in the livedocs.
它在Mac上是错误的,在Safari和FF中,当我调用“socket.close()”命令时,服务器套接字实际上关闭了。在Windoze上,它没有。这是一个很大的问题,因为在SERVER关闭连接之前不会触发Event.CLOSE事件。这是在liveocs。
This is where I'm at. I have no idea why it would work flawlessly on Mac and then be completely busted in 3 different browsers on Windows. The only thing I can come up with is that it's either something in my Windows configuration that's preventing proper communication with the server, or it's the Window Flash player that's causing the problem.
这就是我所处的位置。我不知道为什么它会在Mac上完美运行,然后在Windows上的3种不同浏览器中完全被破坏。我唯一能想到的是,它是我的Windows配置中阻止与服务器正常通信的东西,或者是引起问题的Window Flash播放器。
Any thoughts?
#4
0
We will need more info to resolve this.. What you're saying here appears correct to me. You're using the Socket class to send data though, not ByteArray.
我们需要更多信息来解决这个问题。你在这里说的话对我来说是正确的。您正在使用Socket类来发送数据,而不是ByteArray。
Are you sure data is not being sent? How are you receiving the response? It may be that it's working fine but you're just not aware of it? As i said, tell us more about what you're doing..
您确定没有发送数据吗?你是如何收到回复的?可能它工作正常,但你只是没有意识到它?正如我所说,请告诉我们更多关于你在做什么的事情。
Lee Brimelow has a screencast on gotoAndLearn of writing an POP3 client. It's essentially the same of what you're doing so take a look.
Lee Brimelow播放了关于编写POP3客户端的gotoAndLearn的截屏视频。它与你正在做的事情基本相同,所以看一看。
#5
0
Are you 100% sure the syntax is correct? I know with HTTP you'll have to an include extra linebreak after the request for it to go through. Without it you'll get nothing back. Not sure how it is with FTP though.
你100%确定语法是否正确?我知道使用HTTP,你必须在请求它之后包含额外的换行符。没有它你将得不到任何回报。不知道如何使用FTP。
#6
0
The FTP standard requires CRLF at the end of commands. Try using "\r\n" in place of the "\n" in your example.
FTP标准在命令结束时需要CRLF。尝试使用“\ r \ n”代替示例中的“\ n”。
#7
0
You must serve the CrossDomain Policy File from your FTP server in order to conect correctly.
您必须从FTP服务器提供CrossDomain策略文件才能正确连接。
#8
0
From what I've gathered, you have to send each command one at a time and validate the response before moving on. You should be getting something back against ProgressEvent.SOCKET_DATA
根据我收集的内容,您必须一次发送一个命令并在继续之前验证响应。你应该得到一些反对ProgressEvent.SOCKET_DATA的东西
Try just this and see what you get in response.
试试这个,看看你得到了什么回应。
socket.writeUTFBytes("USER "+user+"\n"); socket.flush();
You would then read the response out like this.
然后你会像这样读出响应。
var response:String = mySocket.readUTFBytes(mySocket.bytesAvailable);
#1
3
The FTP protocol predates UTF encoding. Switch to ANSI/ASCII for better results. If you do opt for writeMultiByte instead of writeUTFBytes, be aware that it is buggy in linux. Here's one way around it.
FTP协议早于UTF编码。切换到ANSI / ASCII以获得更好的结果。如果你选择writeMultiByte而不是writeUTFBytes,请注意它在linux中是错误的。这是绕过它的一种方式。
There's another question here where the line ending turns out to be the culprit, so make sure that you get it right (as suggested above).
这里还有另一个问题,那里的行结尾是罪魁祸首,所以请确保你做对了(如上所述)。
As said before, if this is running from the web, all socket connections will require a crossdomain policy, but this is NOT file based over HTTP. Recent changes to the security rules mean that any socket based connection must first get a crossdomain from a policy server hosted on port 843 of the target host.
如前所述,如果这是从Web运行的,则所有套接字连接都需要跨域策略,但这不是基于HTTP的文件。最近对安全规则的更改意味着任何基于套接字的连接必须首先从目标主机的端口843上托管的策略服务器获取跨域。
Quoting from Adobe:
引用Adobe:
A SWF file may no longer make a socket connection to its own domain without a socket policy file. Prior to version 9,0,115,0, a SWF file was permitted to make socket connections to ports 1024 or greater in its own domain without a policy file.
如果没有套接字策略文件,SWF文件可能不再与其自己的域建立套接字连接。在版本9,0,115,0之前,允许SWF文件在没有策略文件的情况下在其自己的域中建立到1024或更大端口的套接字连接。
HTTP policy files may no longer be used to authorize socket connections. Prior to version 9,0,115,0, an HTTP policy file, served from the master location of /crossdomain.xml on port 80, could be used to authorize a socket connection to any port 1024 or greater on the same host.
HTTP策略文件可能不再用于授权套接字连接。在版本9,0,115,0之前,可以使用从端口80上的/crossdomain.xml的主位置提供的HTTP策略文件来授权到同一主机上的任何1024或更高端口的套接字连接。
Essentially, what this means is that you must be in control of the target FTP host, and install supplementary software on it to get this working.
从本质上讲,这意味着您必须控制目标FTP主机,并在其上安装补充软件才能使其正常工作。
#2
1
Read this link too and maybe it can be useful this one too.
也请阅读此链接,也许这也很有用。
The first one is about policy files and the second is an example of a TELNET (so, no FTP here) client.
第一个是关于策略文件,第二个是TELNET(因此,这里没有FTP)客户端的示例。
#3
1
I've been able to get an FTP client working in a browser, but it's buggy. I had to get a listener running on port 843 to server the policy file so that Flash would be allowed to connect and transfer data. Then, I had to figure out how FTP actually works:
我已经能够在浏览器中使用FTP客户端,但它有问题。我必须在端口843上运行一个侦听器来为策略文件提供服务,以便允许Flash连接和传输数据。然后,我必须弄清楚FTP实际上是如何工作的:
You have to open 2 sockets: a command socket and a data socket. The command socket is where you send your USER, PASS, CWD, and STOR commands. The data socket is where you write your ByteArray data to. Sending the PASV command will tell you what port your data socket must connect to.
您必须打开2个套接字:命令套接字和数据套接字。命令套接字是您发送USER,PASS,CWD和STOR命令的地方。数据套接字是您将ByteArray数据写入的位置。发送PASV命令将告诉您数据套接字必须连接到哪个端口。
Where it is buggy is on Mac, in both Safari and FF, when I call the "socket.close()" command, the server socket actually closes. On Windoze, it does not. This is a huge problem because the Event.CLOSE event is not fired until the SERVER closes the connection. This is in the livedocs.
它在Mac上是错误的,在Safari和FF中,当我调用“socket.close()”命令时,服务器套接字实际上关闭了。在Windoze上,它没有。这是一个很大的问题,因为在SERVER关闭连接之前不会触发Event.CLOSE事件。这是在liveocs。
This is where I'm at. I have no idea why it would work flawlessly on Mac and then be completely busted in 3 different browsers on Windows. The only thing I can come up with is that it's either something in my Windows configuration that's preventing proper communication with the server, or it's the Window Flash player that's causing the problem.
这就是我所处的位置。我不知道为什么它会在Mac上完美运行,然后在Windows上的3种不同浏览器中完全被破坏。我唯一能想到的是,它是我的Windows配置中阻止与服务器正常通信的东西,或者是引起问题的Window Flash播放器。
Any thoughts?
#4
0
We will need more info to resolve this.. What you're saying here appears correct to me. You're using the Socket class to send data though, not ByteArray.
我们需要更多信息来解决这个问题。你在这里说的话对我来说是正确的。您正在使用Socket类来发送数据,而不是ByteArray。
Are you sure data is not being sent? How are you receiving the response? It may be that it's working fine but you're just not aware of it? As i said, tell us more about what you're doing..
您确定没有发送数据吗?你是如何收到回复的?可能它工作正常,但你只是没有意识到它?正如我所说,请告诉我们更多关于你在做什么的事情。
Lee Brimelow has a screencast on gotoAndLearn of writing an POP3 client. It's essentially the same of what you're doing so take a look.
Lee Brimelow播放了关于编写POP3客户端的gotoAndLearn的截屏视频。它与你正在做的事情基本相同,所以看一看。
#5
0
Are you 100% sure the syntax is correct? I know with HTTP you'll have to an include extra linebreak after the request for it to go through. Without it you'll get nothing back. Not sure how it is with FTP though.
你100%确定语法是否正确?我知道使用HTTP,你必须在请求它之后包含额外的换行符。没有它你将得不到任何回报。不知道如何使用FTP。
#6
0
The FTP standard requires CRLF at the end of commands. Try using "\r\n" in place of the "\n" in your example.
FTP标准在命令结束时需要CRLF。尝试使用“\ r \ n”代替示例中的“\ n”。
#7
0
You must serve the CrossDomain Policy File from your FTP server in order to conect correctly.
您必须从FTP服务器提供CrossDomain策略文件才能正确连接。
#8
0
From what I've gathered, you have to send each command one at a time and validate the response before moving on. You should be getting something back against ProgressEvent.SOCKET_DATA
根据我收集的内容,您必须一次发送一个命令并在继续之前验证响应。你应该得到一些反对ProgressEvent.SOCKET_DATA的东西
Try just this and see what you get in response.
试试这个,看看你得到了什么回应。
socket.writeUTFBytes("USER "+user+"\n"); socket.flush();
You would then read the response out like this.
然后你会像这样读出响应。
var response:String = mySocket.readUTFBytes(mySocket.bytesAvailable);