FileZilla兼容FtpAnywhere

运维 系统运维
FileZilla是一个免费开源的FTP客户端软件,分为客户端版本和服务器版本,具备所有的FTP软件功能。可控性、有条理的界面和管理多站点的简化方式使得Filezilla客户端版成为一个方便高效的FTP客户端工具,今天看看FileZilla是如何兼容FtpAnywhere!

 

FileZilla 

图-FileZilla

  FileZilla FTP是一个著名的开源标准FTP客户端软件,但是它的目前版本与FtpAnywhere提供的网格FTP有兼容问题,而且,目前无法通过它提供的那些设置模块来实现兼容,因此,我特地下载了它的源代码快照 [2009.4.16] ,看看是否有可能通过修改源代码来让它兼容.

  解压缩它的源代码,转到子目录\src\engine下,打开ftpcontrolsocket.cpp文件,这个文件就是FileZilla用来支持标准FTP指令的核心,需要改造的是它的列表模式以及对PASV反馈的分析代码 [包括IPV6下的EPSV指令,但是暂时因为没有IPV6,所以没必要动它],改造它的PASV解析代码

  让FileZilla兼容FtpAnywhere

 

  1.   bool CFtpControlSocket::ParsePasvResponse(CRawTransferOpData* pData)  
  2.  
  3.   {  
  4.  
  5.   // Validate ip address  
  6.  
  7.   wxString digit = _T("0*[0-9]{1,3}");  
  8.  
  9.   const wxChar* dot = _T(",");  
  10.  
  11.   wxString exp = _T("( |\\()(") + digit + dot + digit + dot + digit + dot + digit + dot + digit + dot + digit + _T(")( |\\)|$)");  
  12.  
  13.   wxRegEx regex;  
  14.  
  15.   regex.Compile(exp);  
  16.  
  17.   if (!regex.Matches(m_Response))  
  18.  
  19.   return false;  
  20.  
  21.   pData->host = regex.GetMatch(m_Response, 2);  
  22.  
  23.   int i = pData->host.Find(','true);  
  24.  
  25.   long number;  
  26.  
  27.   if (i == -1 || !pData->host.Mid(i + 1).ToLong(&number))  
  28.  
  29.   return false;  
  30.  
  31.   pData->port = number; //get ls byte of server socket  
  32.  
  33.   pData->host = pData->host.Left(i);  
  34.  
  35.   i = pData->host.Find(','true);  
  36.  
  37.   if (i == -1 || !pData->host.Mid(i + 1).ToLong(&number))  
  38.  
  39.   return false;  
  40.  
  41.   pData->port += 256 * number; //add ms byte of server socket  
  42.  
  43.   pData->host = pData-> host.Left(i);  
  44.  
  45.   pData->host.Replace(_T(","), _T("."));  
  46.  
  47.   if (m_pProxyBackend)  
  48.  
  49.   {  
  50.  
  51.   // We do not have any information about the proxy's inner workings  
  52.  
  53.   return true;  
  54.  
  55.   }  

 

  //注意,把下面的代码注销,就可以支持P2P PASV模式下的连接传输了

 

  1.   //const wxString peerIP = m_pSocket->GetPeerIP();  
  2.  
  3.   //if (!IsRoutableAddress(pData->host, m_pSocket->GetAddressFamily()) && IsRoutableAddress(peerIP, m_pSocket->GetAddressFamily()))  
  4.  
  5.   //{  
  6.  
  7.   //if (!m_pEngine->GetOptions()->GetOptionVal(OPTION_PASVREPLYFALLBACKMODE) || pData->bTriedActive)  
  8.  
  9.   //{  
  10.  
  11.   //LogMessage(Status, _("Server sent passive reply with unroutable address. Using server address instead."));  
  12.  
  13.   //LogMessage(Debug_Info, _T(" Reply: %s, peer: %s"), pData->host.c_str(), peerIP.c_str());  
  14.  
  15.   //pData->host = peerIP;  
  16.  
  17.   //}  
  18.  
  19.   //else  
  20.  
  21.   //{  
  22.  
  23.   //LogMessage(Status, _("Server sent passive reply with unroutable address. Passive mode failed."));  
  24.  
  25.   //LogMessage(Debug_Info, _T(" Reply: %s, peer: %s"), pData->host.c_str(), peerIP.c_str());  
  26.  
  27.   //return false;  
  28.  
  29.   //}  
  30.  
  31.   //}  
  32.  
  33.   return true;  
  34.  
  35.   }  

 

  那么现在的代码,只要在站点属性的连接模式里,指定PORT为优先,在PORT模式连接失败后,设置自动切换到PASV模式,已经可以有条件兼容,只是第一次下载会失败而已,下面我们改造它的列表模式,让它具备更好的兼容性. 当然,你可以在FtpAnywhere服务器里,设置禁止根目录下PASV列表,来让FileZilla自动判断连接模式,但是从它的代码看,它的判断还是存在一点兼容问题.因此,将LIST改造成主动模式优先,是最好的选择.

  问题在这里

 

  1.   CRawTransferOpData::CRawTransferOpData()  
  2.  
  3.   : COpData(cmd_rawtransfer)  
  4.  
  5.   {  
  6.  
  7.   bTriedPasv = bTriedActive = false;  
  8.  
  9.   bPasv = true;  
  10.  
  11.   }  

 

  它的初始化是被动模式优先,这样,列表的时候将发生问题,但是下载可以成功,但是我阅读代码,发现除非额外指定一个列表时优先使用的模式变量,否则很难修改代码,因为它的代码中列表和文件传输的优先模式是一致的,还要适应其他标准FTP站点,毕竟我不可以能让它为我的FtpAnywhere进行优化,方法是,在FtpControlSocket.h里定义的类

 

  1.   class CRawTransferOpData : public COpData  
  2.  
  3.   {  
  4.  
  5.   public:  
  6.  
  7.   CRawTransferOpData();  
  8.  
  9.   wxString cmd;  
  10.  
  11.   CFtpTransferOpData* pOldData;  
  12.  
  13.   bool bPasv;  
  14.  
  15.   bool bTriedPasv;  
  16.  
  17.   bool bTriedActive;  
  18.  
  19.   wxString host;  
  20.  
  21.   int port;  
  22.  
  23.   };  

 

  给它加个额外的变量,例如 bool bFtpAnywhere;然后,在List指令前,确定首先采用PASV或者PORT前,判断 bFtpAnywhere是否为真,如果为真,那么列表应该优先采用PORT模式,否则继续执行默认的动作;而bFtpAnywhere的初始化应该从给服务器发送 VDSI指令是否返回2XX来判断,是否是一个FtpAnywhere服务器,因为这里涉及的修改太多,除非FileZilla代码维护人员同意,否则没有意义,因此,最简单最快的方法还是直接注销我上面给出的代码,虽然无法获得100%兼容,但是基本可以兼容,而且通过设置项目,可以做到手动兼容.

通过文章描写和代码的分析,我们可以清楚的知道:FileZilla是兼容FtpAnywhere,希望对大家有用!

【编辑推荐】

  1. 如何解决FileZilla连接不上IIS FTP的问题
  2. Filezilla Server架构FTP服务器
  3. 使用FileZilla进行加密的FTP协议认证
  4. Filezilla的utf-8支持
  5. FileZilla Server提权
  6. FileZilla使用测评
  7. FileZilla实用功能之文件存在处理
  8. FileZilla实用功能之分组管理
  9. 如何实现FileZilla防掉线(反空闲、闲置保护)
责任编辑:赵鹏 来源: 网络转载
相关推荐

2011-03-02 16:46:35

FileZillaFtpAnywhere

2011-03-04 14:02:53

Windows7Filezilla

2011-03-02 09:00:26

2011-03-07 11:26:45

FileZilla

2011-02-23 13:28:12

2011-03-07 09:58:51

FileZilla

2011-03-07 14:08:06

FileZilla配置

2011-02-23 16:40:12

FileZillaSe

2011-03-07 11:36:23

FileZillaSe

2011-03-04 12:18:24

FileZilla

2011-03-04 15:28:33

FileZilla

2011-02-23 16:08:51

FileZilla S

2011-03-07 16:16:14

filezilla s设置

2011-03-07 13:20:12

FileZilla设置

2011-03-07 09:51:12

Filezilla

2011-03-04 16:13:54

FileZilla

2011-03-07 15:07:30

2011-03-04 15:34:52

FileZilla

2011-03-01 17:26:21

2011-03-04 15:21:12

FileZilla
点赞
收藏

51CTO技术栈公众号