[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Patch to add direct FTP proxy support in kio_ftp
From:       Michael Goffioul <goffioul () imec ! be>
Date:       2001-06-27 12:54:22
[Download RAW message or body]

Hi,

Following the small discussion about the problems when using a real FTP
proxy server (not an HTTP proxy, but a real FTP server that acts as a
proxy, like DeLeGate), and after being bored of changing everytime the
'@' char to '%40'. I decided to hack kio_ftp to see if it was possible to
add direct FTP proxy support. Indeed it's only a matter of redirecting 
the connection and using a processed login. This results in the attached
patch, which could be commited to CVS if anybody finds it useful.

Changes are:
- KProtocolManager::proxyForURL : override standard FTP proxy settings 
  if we're using a FTP proxy, to have a direct connection instead of a
  HTTP slave.
- Ftp::openConnection : redirect the connection to a specified host/port
- Ftp::ftpLogin : transform the login into login@remote:port
- Ftp::openDataConnection : enhancement of the PASV disabling

The nice thing with this patch is that now I can simply enter a normal
address like ftp://ftp.kde.org: much easier and no problem anymore with
encoding the '@'.

Configuration takes place in kio_ftprc, using the entries:
UseFtpProxyServer: boolean
FtpProxyServer: string
FtpProxyPort: integer
FtpProxyDisablePASV: boolean

Will it be commited? (just to know if I have to patch my CVS on each update
or not).

Michael.

-- 
------------------------------------------------------------------
Michael Goffioul		IMEC-DESICS-MIRA
e-mail: goffioul@imec.be	(Mixed-Signal and RF Applications)
Tel:    +32/16/28-8510		Kapeldreef, 75
Fax:    +32/16/28-1515		3001 HEVERLEE, BELGIUM
------------------------------------------------------------------
["kio-diff" (text/plain)]

Index: kprotocolmanager.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kprotocolmanager.cpp,v
retrieving revision 1.93
diff -u -r1.93 kprotocolmanager.cpp
--- kprotocolmanager.cpp	2001/06/16 16:06:40	1.93
+++ kprotocolmanager.cpp	2001/06/27 12:43:22
@@ -295,6 +295,11 @@
   QString proxy;
   ProxyType pt = proxyType();
 
+  // this overrides any proxy settings in order to use real FTP
+  // proxy server like DeLeGate
+  if ( url.protocol() == "ftp" && KIO::SlaveConfig::self()->configData( "ftp", \
QString::null, "UseFtpProxyServer" ) == "true" ) +    return QString::fromLatin1( \
"DIRECT" ); +
   switch (pt)
   {
       case PACProxy:
Index: ftp/ftp.cc
===================================================================
RCS file: /home/kde/kdelibs/kio/ftp/ftp.cc,v
retrieving revision 1.141
diff -u -r1.141 ftp.cc
--- ftp/ftp.cc	2001/06/26 18:22:08	1.141
+++ ftp/ftp.cc	2001/06/27 12:43:23
@@ -285,7 +285,25 @@
 
   m_initialPath = QString::null;
 
-  if (!connect( m_host, m_port ))
+  // real values to be used
+  QString r_host( m_host );
+  int r_port ( m_port );
+  MetaData cfgData = KIO::SlaveConfig::self()->configData( "ftp", QString::null );
+  if ( cfgData[ "UseFtpProxyServer" ] == "true" )
+  {
+    bool ok;
+
+    r_host = cfgData[ "FtpProxyServer" ];
+    r_port = cfgData[ "FtpProxyPort" ].toInt( &ok );
+    if ( r_host.isEmpty() )
+      r_host = QString::fromLatin1( "ftpproxy" );
+    if ( r_port <= 0 || !ok )
+      r_port = 8028;
+
+    kdDebug(7102) << "using FTP proxy server host=" << r_host << " port=" << r_port \
<< endl; +  }
+
+  if (!connect( r_host, r_port ))
     return; // error emitted by connect
 
   m_bFtpStarted = true;
@@ -383,6 +401,7 @@
 
   QString user = m_user;
   QString pass = m_pass;
+  bool useFtpProxy = ( KIO::SlaveConfig::self()->configData( "ftp", QString::null, \
"UseFtpProxyServer" ) == "true" );  
   if ( config()->readBoolEntry("EnableAutoLogin") )
   {
@@ -395,7 +414,7 @@
   }
   kdDebug(7102) << "ftpLogin " << user << endl;
 
-  if ( !user.isEmpty() )
+  if ( !user.isEmpty() || useFtpProxy )
   {
     AuthInfo info;
     QCString tempbuf;
@@ -454,6 +473,16 @@
 
       tempbuf = "user ";
       tempbuf += user.latin1();
+      if ( useFtpProxy )
+      {
+        tempbuf += "@";
+        tempbuf += m_host.latin1();
+        if ( m_port > 0 && m_port != 21 )
+        {
+          tempbuf += ":";
+          tempbuf += QString::number( m_port ).latin1();
+        }
+      }
       kdDebug(7102) << "Sending Login name: " << user << endl;
       bool loggedIn = (ftpSendCmd( tempbuf, '2' ) && !strncmp( rspbuf, "230", 3));
       bool needPass = !strncmp( rspbuf, "331", 3);
@@ -814,8 +843,10 @@
   char buf[64];
   int on = 1;
 
+  MetaData cfgData = KIO::SlaveConfig::self()->configData( "ftp", QString::null );
   ////////////// First try passive (EPSV & PASV) modes
-  if ( KIO::SlaveConfig::self()->configData( "ftp", m_host, "DisablePassiveMode" ) \
!= "true" ) +  if ( KIO::SlaveConfig::self()->configData( "ftp", m_host, \
"DisablePassiveMode" ) != "true"  && +       ( cfgData[ "UseFtpProxyServer" ] != \
"true" || cfgData[ "FtpProxyDisablePASV" ] != "true" ))  {
     if (ftpOpenEPSVDataConnection())
       return true;


>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic