首页 > 解决方案 > AS3:协商 FTP-ES 连接

问题描述

我正在尝试修改 ActionScript 3 FTP 库以支持显式安全 (FTP-ES) 连接。

使用 FTP-ES,客户端最初建立一个不安全的 FTP 连接,然后明确要求服务器切换到安全的 SSL/TLS 连接。

现在,我最初使用常规 Socket 连接到 FTP 服务器,要求服务器切换到 TLS,然后在服务器返回 FTP 代码 234 后尝试使用 SecureSocket 连接:

if (code.indexOf('220 ') == 0 || code.indexOf('220-') == 0) { //Send user name
    if (_useTLS) {
        trace("AUTH TLS");
        cmdSocket.writeUTFBytes('AUTH TLS\r\n');
    } else {
        cmdSocket.writeUTFBytes('USER ' + _username + '\r\n');
    }
    cmdSocket.flush();
}

if (responseCode.indexOf('234 ') == 0) { //Auth OK, expecting SSL/TLS negotatiation
    if (SecureSocket.isSupported) {
        secureCommandSocket = new SecureSocket();
        secureCommandSocket.addEventListener(ProgressEvent.SOCKET_DATA, onReceivedSCmd);
        secureCommandSocket.addEventListener(Event.CONNECT, onConnectSCmd);
        secureCommandSocket.addEventListener(IOErrorEvent.IO_ERROR, onSocketError);
        secureCommandSocket.addEventListener(Event.CLOSE, onCloseSCmd);
        secureCommandSocket.connect(_host, _port);
    } else {
        throw new Error("Secure socket is not supported on this platform");
    }
}

但是,套接字返回 IOError 2031(套接字错误)。这是输出:

MESSAGE: CONNECTED TO FTP
MESSAGE: Received command: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 1 of 50 allowed.

AUTH TLS
MESSAGE: Received command: 234 AUTH TLS OK.

MESSAGE: 2031:Error #2031: Socket Error. URL: xx.xx.xxx.xx
ERROR: Connection failed

由于没有更多关于出了什么问题的信息,我不知道为什么安全套接字连接失败了。是因为我试图从常规 Socket 切换到 SecureSocket 中间连接吗?如果是这样,在 AS3 中有没有其他方法可以处理这个问题?

标签: actionscript-3ftpftpes

解决方案


推荐阅读