I'm using python with ftplib
to upload images to a folder on my raspberryPi located in /var/www.
Everything is working fine except that uploaded files have 600
permissions and I need 644
for them.
Which is the best way to do this? I'm searching for something like:
def ftp_store_avatar(name, image):
ftp = ftp_connect()
ftp.cwd("/img")
file = open(image, 'rb')
ftp.storbinary('STOR ' + name + ".jpg", file) # send the file
[command to set permissions to file]
file.close()
ftp.close()
Right click on the file name and select "File permissions" from the drop down menu. In the Change file attributes window that opens, change the "Numeric value" permission to 644 to give the Owner permission to Read, Write, and Execute. Click on OK to continue.
Right-click on the name of the folder/file you want to change the permissions for and click on File Permissions. A new window will pop-up. In it, use the checkboxes to set the desired permissions or alternatively use the Numeric value text box and input the numeric value of the desired permissions.
Use os.chmod(path, mode) to change the file permissions to mode for the file located at path . To set multiple permissions, use the OR | operator to combine permission flags. Further reading: There are many different flags in the stat module.
You need to use sendcmd.
Here is a sample program that changes permissions via ftplib:
#!/usr/bin/env python
import sys
import ftplib
filename = sys.argv[1]
ftp = ftplib.FTP('servername', 'username', 'password')
print ftp.sendcmd('SITE CHMOD 644 ' + filename)
ftp.quit()
Happy programming!
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