Possible to zip a file (files?) and then unzip once uploaded or is upload and rename the only option?

StackOverflow https://stackoverflow.com/questions/20134977

Question

I have no idea if this is possible...

Let's say I want to put test.html into a .zip archive and then use ftplib to upload the file and then once uploaded for it to be extracted overwriting any files?

If that's not possible whats the best way to upload a file, then rename and overwrite the original file name (would I have to delete the original test.html from the ftp folder?)

Any ideas?

ftp_session = ftplib.FTP('ftp.website.com','admin@website.com','password123')
ftp_file = open('output.html','r')
ftp_session.cwd("/folder")
ftp_session.storlines('STOR output.html', ftp_file)
ftp_file.close()
ftp_session.quit()
Was it helpful?

Solution

The FTP server won't unzip your file, you'll have to have something running on the other side doing that.

If you want to replace a single file, upload it as test.html.tmp and then rename it to test.html. The rename (ftp operation) should be atomic (filesystem wise) and will overwrite the old file (actually just delete it and point the name to the new file). This way, anything reading the file will get either the old version or the new one, but correctly, no danger of reading just half the new file.

I think that using CPanel you'll run unzip, which most likely will open the file for writing, truncate it and then fill the content. This is not atomic, someone may read invalid file. On the other hand, you can write a script that will run remotely and do the thing the way you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top