FIND/CHMOD combined

I am trying to change permission for all subdirectories and files inside folder1 so this is what i came with after many seraches on the internet. man find and man chmod mirc and few articles.

find .public_html/folder1 -print0 | xargs -0 chmod 777

what's wrong with this command?
it is FTP Server btw, if it means something at all :slight_smile:

Thanks :b:

<edit>
Ah i nearly forgot to say that i also tried with recursive method of the CHMOD command:

chmod -R 777 public_html/folder1

Am i missing some sign to the start something at the end maybe?
Thanks ones again :slight_smile:

What is most important sending a command for a single file/dir works flawless:

chmod 755 folder1/index.html

Why i just cannot execute the same command in a recursive flavour ?

Probably because it can't treat files and directories the same?

Try "find ... -print -type f | xargs -n 1 chmod 777"

the "xargs -n 1 ...." means do a command per argument
the "find ... -type f" means only print files

Nothing happens:

find /public_html/* -print -type f | xargs -n 1 chmod 755

no errors but also not affected files :frowning:

Maybe i am doing something wrong with the slashes? please check that code ones again. Thanks a lot :b:

Not promising anything but try

find <dir> -type f -exec chmod 777 {} \;

I believe that to change the permissions on a file you have to be the owner or root

Nope ! the same result. Nothing happens :slight_smile:

Maybe i should mention that i am executing this command from C# code.
Actually i am trying to send this command from C# FTP Client and please notice that it works flawless if i target only single file or directory. I just cannot make it to works for all files and dirs inside the selected directory. in a recursive manner.

For example this is the code that change permissions for index.html file:

TcpClient tcpClient = new TcpClient();
tcpClient.Connect(this.txtServerAddress.Text, Convert.ToInt32(this.txtPortNumber.Text));
NetworkStream netStream = tcpClient.GetStream();
System.IO.StreamReader strReader = new System.IO.StreamReader(netStream);

byte[] WriteBuffer = new byte[1024];

//passing ASCII characters 
ASCIIEncoding enc = new System.Text.ASCIIEncoding();

// Pass the username to the server
WriteBuffer = enc.GetBytes("USER " + "username" + "\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
// Read the server response line from the stream reader
MessageBox.Show(strReader.ReadLine());

// Pass the password to the server
WriteBuffer = enc.GetBytes("PASS " + "password" + "\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
// Read the server response line from the stream reader
MessageBox.Show(strReader.ReadLine());

//CHANGE PERM. OF INDEX.HTML
WriteBuffer = enc.GetBytes("CHMOD 775 " + "public_html/index.html" + "\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
// Read the server response line from the stream reader 
MessageBox.Show(strReader.ReadLine());

tcpClient.Close();

As i said this code works like a charm changing permission of index.html

Thanks for any further help :slight_smile:

*BUMP*

C'mon guys !!! I know this is an easy task for you. I am not tending to learn UNIX programming just this time and i am gone. Just give me some ideas ... !!
Thanks :slight_smile:

Are you sure you're dealing with a unix machine? chmod in UPPER case should not work on unix.

what would be the difference if it's a Linux (some of the distro's) ???
Anyway it remains that UPPER case command works flawless for a single file/dir.
Thanks for any further help :slight_smile:

Unix/Linux is case sensitive, Windows is not. The fact that you can execute CHMOD would mean that either there is a non standard upper case chmod command or that you may not be executing on unix. You may be executing on Windows with some unix like commands.

I suppose another explanation maybe that your code is some how translating to lower case. Or maybe there's some variant of unix that I am unaware of that is not case sensitive.

You start by asking one question then later explain that the scenario is then totally different. Commands executed in an ftp session have nothing to do with commands executed within a shell.

If these are commands executed within an ftp session you are restricted to those.

If you want to run commands under a shell then use ssh or equivalent.

Well from the beginning i thought that it's just a command that should behave same if you type in command .. and if you send through TCP connection.
Anyway please notice that it is a direct TCP connection with the server. FTP has nothing to do with that. I've just mentioned the FTP in order to inform you about the idea otherwise i open new TCP connection and send those commands:

TcpClient tcpClient = new TcpClient();
tcpClient.Connect(this.txtServerAddress.Text, Convert.ToInt32(this.txtPortNumber.Text));

So if there is one who knows what the problem is please let me know.

Thanks for any further help.

What port are you connecting to? SSH? Telnet? FTP? rsh? rexec? HTTP?

Ok i got your point i do connecting to the port #21 (FTP) instead 22 which is default port for SSH but how do you explain the fact that it works fine when i target a single file/directory?
Thanks for the patient :slight_smile:

This works because you are talking raw FTP to it, so any of the FTP commands, which are a very small subset of the shell commands, will work.

I suggest that instead of trying to talk raw TCP to a UNIX host, you use an intermediary such as Putty's plink.exe to talk SSH. So spawn this with CreateProcess using unamed pipes as stdin, stdout and stderr. Let plink.exe do all the login etc, you can then send the shell commands down the pipe.

I am sure that your suggestion is leading toward one solution but i am afraid i don't like to use 3rd party products/libraries/whatever. :frowning:
It would be nice if i can find a pure C# .NET code that can send "CHMOD -R xxx <DIR>" through SSH or SSH2.

Thanks :slight_smile:

... from a 3rd party?

With all respect for your time and intentions;
I am already not sure what is your idea? are you trying to help? If so please don't ask me a questions. Your suggestions seem not clear enough as i am just a n00b in this and as i said i am not tending to learn UNIX in depth. Just this case and i quit.
Thanks for understanding. And Please no offense; if you find any insultive statement in my posts that's because of the language barrier (English is not my native language so i maight to say something that could be understood a bit different than my original idea)

Thanks :slight_smile:

you can try the command directly, it works fine, so if anything is wrong, it can be the command line.

I've tried this: find ./ -print | xargs chmod 777
it changes all directory and files under current directory

find ./ -print | xargs chmod -R 777

But make sure do you have write permission for these directories/Files or NOT