[Tutor] FTP File Size

Jörg Wölke lumbricus@gmx.net
Tue, 19 Mar 2002 15:58:55 +0100 (MET)


> Hello:

Hi!
 
> 
> > What kind of ftp server?
> 
>   Must ask domain hoster, but my guess is wu_ftpd, or FtpPro on
>   RH linux. The clients I'm using (Midnight Commander and IglooFTP)
>   are reporting correctly, I believe.
> 
> > If its open source, how does it determine the size?
>   
>    I'm using an object that inherits FTP from ftplib. 
>    => using the "original" (not overloaded) 'size' method.
>    I can send entire source if necessary.

No, the problem is, how the _server_ determines the
file size. Because ftplib.py just sends the size
command and prints the answer.

from my ftplib.py:

| def size(self, filename):
|                '''Retrieve the size of a file.'''
|                # Note that the RFC doesn't say anything about 'SIZE'
|                resp = self.sendcmd('SIZE ' + filename)
|                if resp[:3] == '213':
|                        return string.atoi(string.strip(resp[3:]))

$ perl -e 'print "X"x2023' > test.txt
$ telnet localhost 21
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 ******.uni-freiburg.de FTP server (Digital UNIX Version 5.60) ready.
user guest
331 Password required for guest.
pass ******
230 User guest logged in.
size test.txt
213 File size (test.txt): 2023 bytes
quit
221 Goodbye.
Connection closed by foreign host.
$ rm test.txt
$  

Here it seems to work correctly.
Don't know how "sparse files" are influencing
the servers answer to the 'SIZE' command.

HTH, HAND 
and Greetings J"o!

-- 
sigfault

GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net