I have logged into a server via sftp via terminal.
When I run the command
chmod -R 755 ./*I get the error You must supply a numeric argument to the chmod command.. How do I apply a recursive chmod 755 while in sftp?
3 Answers
You may not be able to. There's a good chance the chmod available to you via FTP or SFTP does not support the recursive option. Commands available under FTP/SFTP are often somewhat crippled versions of what you'd have available locally under the shell. If you're lucky, chmod may act recursively even without the -R option but if you're unlucky, you'll have to traverse the tree, chmod'ing each level one-at-a-time.
From man sftp:
chmod mode pathChange permissions of file path to mode. path may contain glob(3) characters and may match multiple files.
man 7 glob (man 3 glob references glob(7)) describes the *, ? and [] wildcard patterns we are familiar with when using ls. So you could use:
chmod 755 ./*
chmod 755 ./*/*
chmod 755 ./*/*/*repeatedly until you have reached all files and get the error:
Couldn't setstat on "./*/*/*": No such file or directoryBefore such a mass change, you could double-check in advance which directories would be affected with lls (from man sftp):
lls [ls-options [path]]Display local directory listing of either path or current directory if path is not specified. ls-options may contain any flags supported by the local system's ls(1) command. path may contain glob(3) characters and may match multiple files.
like this (specify an absolute path to lls to avoid surprises):
lls -Rla /pathYou can also use lls -Rla /path to make sure your chmod worked as expected.
I was working on a server where the recursive did not seem to be supported as per Nicole's comment above. The wildcard chmod did work, but was timing out trying to run on the insane folder structure.
What did the trick for me in the end was actually Filezilla - although I couldn't recursively chmod via terminal, Filezilla was able to do it somehow via it's GUI.