FileZilla FTP 兼容FtpAnywhere

运维 系统运维
FileZilla FTP是一个著名的开源标准FTP客户端软件,但是与FtpAnywhere提供的网格FTP有兼容问题。所以如何才能让FileZilla FTP 兼容FtpAnywhere呢?本文主要讲述的就是这个问题:让FileZilla FTP 兼容FtpAnywhere

  让FileZilla兼容FtpAnywhere

  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.   }  
  56.  
  57.   const wxString peerIP = m_pSocket->GetPeerIP();  
  58.  
  59.   if (!IsRoutableAddress(pData->host, m_pSocket->GetAddressFamily()) && IsRoutableAddress(peerIP, m_pSocket->GetAddressFamily()))  
  60.  
  61.   {  
  62.  
  63.   if (!m_pEngine->GetOptions()->GetOptionVal(OPTION_PASVREPLYFALLBACKMODE) || pData->bTriedActive)  
  64.  
  65.   {  
  66.  
  67.   LogMessage(Status, _("Server sent passive reply with unroutable address. Using server address instead."));  
  68.  
  69.   LogMessage(Debug_Info, _T(" Reply: %s, peer: %s"), pData->host.c_str(), peerIP.c_str());  
  70.  
  71.   pData->host = peerIP;  
  72.  
  73.   }  
  74.  
  75.   else  
  76.  
  77.   {  
  78.  
  79.   LogMessage(Status, _("Server sent passive reply with unroutable address. Passive mode failed."));  
  80.  
  81.   LogMessage(Debug_Info, _T(" Reply: %s, peer: %s"), pData->host.c_str(), peerIP.c_str());  
  82.  
  83.   return false;  
  84.  
  85.   }  
  86.  
  87.   }  
  88.  
  89.   return true;  
  90.  
  91.   }  
  92.  

  这里是它原先的代码,导致PASV模式下无法下载的问题就出在它不知道有P2P传输这么个东西,因此加了个安全判断功能,只要把它注销就可以适合FtpAnywhere了,一般来说,只要FTP服务器是正规的服务器,那么这些代码完全是白费蜡,注销后的代码

  让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.   }  
  56.  
  57.   //注意,把下面的代码注销,就可以支持P2P PASV模式下的连接传输了  
  58.  
  59.   //const wxString peerIP = m_pSocket->GetPeerIP();  
  60.  
  61.   //if (!IsRoutableAddress(pData->host, m_pSocket->GetAddressFamily()) && IsRoutableAddress(peerIP, m_pSocket->GetAddressFamily()))  
  62.  
  63.   //{  
  64.  
  65.   //if (!m_pEngine->GetOptions()->GetOptionVal(OPTION_PASVREPLYFALLBACKMODE) || pData->bTriedActive)  
  66.  
  67.   //{  
  68.  
  69.   //LogMessage(Status, _("Server sent passive reply with unroutable address. Using server address instead."));  
  70.  
  71.   //LogMessage(Debug_Info, _T(" Reply: %s, peer: %s"), pData->host.c_str(), peerIP.c_str());  
  72.  
  73.   //pData->host = peerIP;  
  74.  
  75.   //}  
  76.  
  77.   //else  
  78.  
  79.   //{  
  80.  
  81.   //LogMessage(Status, _("Server sent passive reply with unroutable address. Passive mode failed."));  
  82.  
  83.   //LogMessage(Debug_Info, _T(" Reply: %s, peer: %s"), pData->host.c_str(), peerIP.c_str());  
  84.  
  85.   //return false;  
  86.  
  87.   //}  
  88.  
  89.   //}  
  90.  
  91.   return true;  
  92.  
  93.   }  
  94.  

#p#

  那么现在的代码,只要在站点属性的连接模式里,指定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.   }  
  12.  

  它的初始化是被动模式优先,这样,列表的时候将发生问题,但是下载可以成功,但是我阅读代码,发现除非额外指定一个列表时优先使用的模式变量,否则很难修改代码,因为它的代码中列表和文件传输的优先模式是一致的,还要适应其他标准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.   };  
  24.  

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

【编辑推荐】

  1. FileZilla Ftp 教程
  2. FileZilla客户端高级体验(图)
  3. FTP客户端 Filezilla
  4. FileZilla Server 安装设置(图)
  5. FileZilla FTP server 安装配置(图)
  6. 用FileZilla共享文件Win7和Centos5虚拟机(图)
  7. Filezilla server 安装指南
  8. FileZilla FTP Server安装教程
责任编辑:zhaolei 来源: CSDN
相关推荐

2011-03-07 14:34:50

FileZillaFtpAnywhere

2011-03-02 09:00:26

2011-03-07 14:23:08

2011-03-04 12:00:47

FileZilla

2011-03-02 14:36:24

Filezilla客户端

2011-03-01 16:50:19

2011-03-07 14:32:54

FileZilla帐户

2011-03-07 14:36:36

2011-03-07 14:36:36

2011-03-07 15:51:41

FileZilla

2011-03-04 10:35:39

FileZilla

2011-03-04 14:02:53

Windows7Filezilla

2011-03-07 13:36:16

2011-03-01 17:38:07

FileZilla安装

2011-03-04 11:51:00

FileZilla用户组

2011-03-07 13:12:58

FileZilla

2021-11-01 07:15:36

服务器FTPFileZilla

2011-03-01 16:25:37

FileZilla

2011-03-04 11:23:55

FileZilla

2011-03-01 16:32:58

FileZilla
点赞
收藏

51CTO技术栈公众号