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.
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
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
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
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.
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
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.
It would be nice if i can find a pure C# .NET code that can send "CHMOD -R xxx <DIR>" through SSH or SSH2.
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)