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.
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.
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()
Any suggestions?
Answer: There is not a limit on the size of the file. But keep in mind that the bigger the file the longer it will take to be transferred. However, either a ReadTimeout or OutOfMemory message may appear, depending on how many files are on the ftp server, and how large the files are.
In $files you should get one line per file, containing file permissions, owner/group, filesize and filename. You will have to parse this to display them separately. DISCLAIMER : Just copy/pasted the connection info from the CI manual, added the last line based on the CI source code, YMMV :p. Show activity on this post.
Uploading via FTP clientIf you have an FTP client like FileZilla, transferring files is a simple three-step process. Open FileZilla from your desktop or Start menu. Type in the following at the top and click Quickconnect. Drag and drop the relevant files into the upload folder.
Accessing multiple smaller files can be slower than accessing a large file. Parsing time. Parsing a large file will take more time than a small one. If you are parsing more than you need, then you are wasting time.
Do you need to open the locfile in binary using rb
?
f = open (locfile, "rb")
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.
So you might be comparing the sector file size to the actual file size on the FTP server or vice versa.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With