<p>I have created a PHP-script to update a web server that is live inside a local directory.
I'm migrating the script into Python. It works fine for the most part, but after a PUT command, the size of the file appears to change. Thus, the size of the file is different from that of the file on the server. </p>

<p>Once I download again the file from the FTP server, the only difference is the CR/LF mark. This annoys me because the same script is comparing the size of the files to update. Also, in case it means anything, the script works perfectly in PHP vía ftp_put.</p>

<pre><code>from ftplib import FTP

ftpserver = "myserver"
ftpuser = "myuser"
ftppass = "mypwd"

locfile =  "g:/test/style.css"
ftpfile =  "/temp/style.css"

try:
    ftp = FTP(ftpserver, ftpuser, ftppass)
except:
    exit ("Cannot connect")

f = open (locfile, "r")
try:
    ftp.delete (ftpfile)
except:
    pass

# ftp.sendcmd ("TYPE I")
# ftp.storlines("STOR %s" % ftpfile, f)
ftp.storbinary("STOR %s" % ftpfile, f)
f.close()

ftp.dir (ftpfile)
ftp.quit()
</code></pre>

<p>Any suggestions?</p>

[{'answer_id': 2316, 'author': 'David Sykes', 'author_id': 259, 'author_profile': 'https://Stackoverflow.com/users/259', 'pm_score': 5, 'selected': True, 'text': '<p>Do you need to open the locfile in binary using <code>rb</code>?</p>\n\n<pre><code>f = open (locfile, "rb")\n</code></pre>\n'}, {'answer_id': 2317, 'author': 'Nick Berardi', 'author_id': 17, 'author_profile': 'https://Stackoverflow.com/users/17', 'pm_score': 2, 'selected': False, 'text': '<p>Well if you go under the properties of your file in Windows or a *nix environment, you will notice two sizes.  One is the sector size, and one is the actual size.  The sector size is the number of sectors in bytes that are used up on your hard disk.  That is because two files cannot be in the same sector with most modern file systems, so if your file fills up half of the sector the whole sector is marked as filled.</p>\n\n<p>So you might be comparing the sector file size to the actual file size on the FTP server or vice versa.</p>\n'}, {'answer_id': 2510, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 0, 'selected': False, 'text': "<p>Small files take up a whole node on the file system whatever the size is.</p>\n<p>My host tends to report all small files as 4KB in ftp but gives an accurate size in a shell so it might be a 'feature' common to ftp clients.</p>\n"}]
['https://Stackoverflow.com/questions/2311', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/394/']