• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

FTP scripting on unix?

kukyfrope

Senior member
I'm trying to learn how to create a script that can SFTP into a server, issue chmod all directories in 1 specific main directory, and then chmod 1 file (same name across all dir's) in each directory of the main directory. This would be executed manually by a user possibly without shell access. Could somebody throw something out there as a solution or give me a place to start? Thanks!
 
sftp isn't really made for this, are you using sftp just so you don't have to give that user account a shell? And what are you doing that's breaking the permissions in the first place, that would seem to be the logical place to fix the issue.
 
SFTP is a security measure for the server itself and is required to connect.

The permissions are not breaking. The user is publishing new HTML and streaming media to the web via a program made by Accordent Technologies. We have modified the files to run some required scripting and the server requires the files to be 700, opposed to the 664 that Accordent publishes them as. The cilent is not too web savvy, but is capable of using an FTP app to manually login and chmod new files, but I figured it was something that could be done much easier with a script and would be a learning process for me as well.

We could setup the client to login via putty and run a script that lives on the server also. I just didn't know if it was worth explaining to them.
 
SFTP is a security measure for the server itself and is required to connect.

I know what sftp is, but it's just a subsystem of ssh and ssh would be better for normal command scripting.

The user is publishing new HTML and streaming media to the web via a program made by Accordent Technologies. We have modified the files to run some required scripting and the server requires the files to be 700, opposed to the 664 that Accordent publishes them as. The cilent is not too web savvy, but is capable of using an FTP app to manually login and chmod new files, but I figured it was something that could be done much easier with a script and would be a learning process for me as well.

Is there a way to change Accordent's (or the account it logs in as) umask so that they get created as 700?
 
I made the statement about SFTP to state that it's required at the server level and I can't change that setting on the server. I had no dobut you knew what it was 😉

The current umask on the account is 0002. Could I specify a default permission for all .shtml that upload under a certain directory (since I don't want them to be executable in other directories) or can it only affect account-wide? Could it be session-based, or set on connect then reset on disconnect in some way? SHTML needs execute permissions because we're running the scripts via suexec.

Forgive my lack of unix command knowledge and thanks for the help so far Nothinman 🙂
 
I made the statement about SFTP to state that it's required at the server level and I can't change that setting on the server. I had no dobut you knew what it was

Well if you have no control over the server and sftp is it, then I guess that's it =)

The current umask on the account is 0002.

Well then you could probably get them created as 600 by changing the umask, but not 700 since the umask specifies what permissions to take a way from the rights given in the open(2) call.

Now the real question is where will this script be run? If it's a Windows box you'll have a more difficult time since there's no ssh/sftp clients that come with it. Giving them putty and having them run the script on the server is probably the easier solution, unless there's an SFTP client for Windows that can do the scripting you need. The unix script would be just a few find/chmod commands but via an FTP client would probalby be more complicated.
 
CURL has wrappers in a number of scripting languages - I've used it with Python quite a bit. But I've never worked with SFTP.
 
Looking at the man page it looks like you can use the -Q option to have it execute commands before or after the transfer, so it would be better to integrate that with the initial upload process instead of a bandaid for fixing the permissions afterwards.
 
Back
Top