FLEX2 ftp客户端

 

<? xml version = " 1.0 "  encoding = " utf-8 " ?>
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml "  layout = " absolute " >
    
< mx:Label x = " 10 "  y = " 10 "  text = " 服务器: "  width = " 53 "  fontSize = " 12 " />
    
< mx:TextInput x = " 71 "  y = " 10 "  width = " 208 "  editable = " true "  id = " Server " />
    
< mx:TextInput x = " 71 "  y = " 38 "  width = " 208 "  editable = " true "  id = " UserName " />
    
< mx:TextInput x = " 71 "  y = " 66 "  width = " 208 "  editable = " true "  id = " Password "  displayAsPassword = " true " />
    
< mx:HRule x = " 10 "  y = " 94 "  width = " 538 " />
    
< mx:TextArea x = " 10 "  y = " 104 "  width = " 538 "  height = " 280 "  id = " DebugText " />
    
< mx:Button x = " 287 "  y = " 65 "  label = "  连 接  "  id = " Submit "  click = " Send() " />
    
< mx:Style >
        Application 
{
           backgroundColor: #869ca7;
           backgroundGradientColors: #6666ff, #ff3399;
           themeColor: #66ff00;
           color: #0b333c;
        }

        Button 
{
               fontSize: 
12;
        }

    
</ mx:Style >
< mx:Script >
    
<! [CDATA[
        
import  mx.events.IndexChangedEvent;
        
import  flash.net. * ;
        
import  flash.utils.ByteArray;
        
import  mx.controls.Alert;
        
        
private  var hostname:String;
        
private  var port: int   =   21 ;
        
private  var username:String;
        
private  var password:String;
        
private  var socket:Socket;
        
private  var State:String;
        
private  var str:String;
        
private  var event:Event;
        
        
public  function Send(): void {
            hostname 
= Server.text;
            username 
= UserName.text;
            password 
= Password.text;
            socket 
= new Socket;
            AddListeners(socket);
            socket.connect(hostname,port);
            traces(
"连接"+hostname+"");
        }

        
        
private  function AddListeners(event:IEventDispatcher): void {
            socket.addEventListener(
"connect", OnConnect);
            socket.addEventListener(
"progress", DataActive);
            socket.addEventListener(
"socketData", RevData);
            socket.addEventListener(
"ioError", Err);
            socket.addEventListener(
"securityError", Err);
        }

        
        
private  function OnConnect(event:Event): void {
            traces(
"连接成功"+event);
        }

        
        
private  function RevData (event:Event): void {
            traces(
"接收数据"+event);
            var input:String
="";
            
while ( socket.bytesAvailable > 0 )
            
{
                var 
byte: uint = socket.readUnsignedByte();
                var next: uint;
                   input 
+= String.fromCharCode( byte );
               }

               State
=input.substr(0,3);
               
//Alert.show(State,"Debug");
               traces("接收数据:"+input);
               DataActive(State);
        }

        
        
private  function DataActive(State:String): void {
            traces(
"发送数据状态激活");
            
switch (State){
                
case "220":
                
{
                    str 
= "USER "+username+" ";
                    
break;
                }

                
case "331":
                
{
                    str 
= "PASS "+password+" ";
                    
break;
                }

                
case "230":
                
{
                    str 
= "PWD ";
                    
break;
                }

                
case "227":
                
{
                    str 
= "LIST ";
                    
break;
                }

                
case "257":
                
{
                    str 
= "REST 0 ";
                    
break;
                }

                
case "350":
                
{
                    str 
= "PASV ";
                    
break;
                }

                
case "530":
                
{
                    str 
= "USER "+username+" ";
                    
break;
                }

            }

            socket.writeMultiByte(str,
"iso-8859-2");
            socket.flush();
            State 
== "331" ? traces("发送数据******") : traces("发送数据"+str);
        }

        
private  function Err(event:Event): void {
            traces(
"错误:"+event);
        }

        
private  function traces(msg:String): void {
            DebugText.text 
= DebugText.text + " " + msg;
        }

    ]]
>
</ mx:Script >     
    
< mx:Label x = " 10 "  y = " 38 "  text = " 用户名: "  fontSize = " 12 " />
    
< mx:Label x = " 18 "  y = " 66 "  text = " 密 码: "  fontSize = " 12 " />
</ mx:Application >

 

演示

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值