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

List:       kfm-devel
Subject:    Another kfm fix, for FTP protocol
From:       David Faure <David.Faure () insa-lyon ! fr>
Date:       1999-01-26 9:39:18
[Download RAW message or body]

You might have noticed that from some FTP servers, every file you try to
download with kfm arrives empty on your hard disk.

The attached patch fixes it.
Please test it, I think it's an important fix that I would like to see in
1.1

As for the other one, please send me an e-mail if you tested it, even if it 
worked flawlessly, otherwise I'll never know if I can apply it.

BTW, master.kde.org in such a server !
(Couldn't test on ftp.kde.org)

-- 
 ____________________________________________________________________
|                                                                    |
|  David FAURE                                                       |
|  E-mail : David.Faure@insa-lyon.fr, faure@kde.org                  |
|  http://www.insa-lyon.fr/People/AEDI/dfaure/index.html             |
|____________________________________________________________________|

["patch.ftp.size" (text/plain)]

Index: ftp.cpp
===================================================================
RCS file: /home/kde/kdebase/kfm/kioslave/ftp.cpp,v
retrieving revision 1.18
diff -u -p -r1.18 ftp.cpp
--- ftp.cpp	1999/01/12 18:08:55	1.18
+++ ftp.cpp	1999/01/26 09:28:43
@@ -311,6 +311,17 @@ int KProtocolFTP::ftpPort(void)
     return 1;
 }
 
+/** Use the SIZE command to get the file size. David. */
+long KProtocolFTP::ftpSize( const char *path)
+{
+    char buf[256];
+    ftplib_lastresp[0] = '\0';
+    sprintf(buf,"SIZE %s",path);
+    if (!ftpSendCmd(buf,'2'))
+	return FAIL;
+    return atol(rspbuf+4); // skip leading "213 " (response code)
+}
+
 /*
  * ftpMkdir - create a directory at server
  *
@@ -666,12 +677,15 @@ int KProtocolFTP::Open(KURL *url, int mo
     if(Connect(url) == FAIL) return(FAIL);
     if(mode & READ)
     {
+        size = ftpSize(url->path()); // try to find the size of the file
+        if (ftplib_debug > 1)
+            fprintf(stderr,"size set to %ld",size);
 	int rc = OpenConnection("retr",url->path(),'I');
 	if(rc == FAIL)
 	    return Error(KIO_ERROR_FileDoesNotExist,"Could not retrieve file");
     
-    	// Read the size from the response string
-    	if ( strlen( rspbuf ) > 4 )
+    	// Read the size from the response string, if the "size" command failed
+    	if ( strlen( rspbuf ) > 4 && size == FAIL )
     	{
 	    // char *p = strchr( rspbuf, '(' );
 	    // Patch from Alessandro Mirone <alex@greco2.polytechnique.fr>
Index: ftp.h
===================================================================
RCS file: /home/kde/kdebase/kfm/kioslave/ftp.h,v
retrieving revision 1.8
diff -u -p -r1.8 ftp.h
--- ftp.h	1998/12/22 06:59:45	1.8
+++ ftp.h	1999/01/26 09:28:43
@@ -49,6 +49,7 @@ private:
 	int ftpSendCmd(const char *cmd, char expresp);
 	int ftpLogin( const char *user, const char *pass, QString *redirect = 0L);
 	int ftpPort();
+        long ftpSize( const char *path);
 	int ftpMkdir(const char *path);
 	int ftpChdir( const char *path);
  	int ftpRmdir( const char *path);


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

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