Java and .NET components, FTP, TELNET, SMTP, POP3, IMAP, HTTP, SSH
Home Search Knowledge Base Support

Support

Click here for access to live sales support.

For technical support please submit a ticket to the Help Desk.

 

Java and .NET Help

iPod shuffle offer

For a limited time get the newly re-designed iPod shuffle free with qualifying purchase.

Click for details.


News

Secure iNet Factory 8.0 Released
04/04/2008 02:24 PM

Updates to Email Factory for .NET and Secure iNet Factory
03/29/2008 04:06 PM

JSCAPE Secure FTP Server 3.9 Preview
03/14/2008 12:19 PM

AnyClient Service and Application Launched
03/12/2008 03:41 PM

JSCAPE Secure FTP Server 3.8 Released
02/12/2008 10:50 AM


Tutorials

Email Validation with Java
04/15/2008 02:04 PM

Sending HTML Based Email Using Java
03/11/2008 02:47 PM

Secure FTP Using Java and FTPS (FTP over SSL)
03/10/2008 04:08 PM

FTP Directory Listing Using Java
03/10/2008 03:57 PM

Sending Email Using Java
03/09/2008 03:43 PM

SSH Using Java
03/09/2008 02:53 PM


Articles

DMZ File Transfer Streaming
03/28/2008 11:57 AM

Phishing looks to FTP to distribute malware
03/13/2008 05:14 PM

Ad Hoc File Transfer Explained
03/13/2008 09:16 AM

Password Policies Made Easy
03/12/2008 03:03 PM


Feedback

Request a feature or component

Request a Java or .NET component


 

Changing Remote File Permissions - Part 2

Page 1  Page 2  Page 3

Adding the FormPermissions.cs code

The following code list is only a portion of the FormPermissions.cs file. You can view the complete source code in the download for this article.

We'll create a control array to hold our permission selections on the permissions form. Note that this is a very simplified means to work around no longer having control arrays built into .NET. You could dynamically create the checkbox controls using a control class, but for the purposes of this article a control array will suffice.

public class FormPermissions : System.Windows.Forms.Form {
/*
 * CODE REMOVED FOR CLARITY
 */
// create our control array public CheckBox[] cbPerms = new CheckBox[9];
public FormPermissions() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call //
// define each item in array cbPerms[0] = this.owner_read; cbPerms[1] = this.owner_write; cbPerms[2] = this.owner_execute; cbPerms[3] = this.group_read; cbPerms[4] = this.group_write; cbPerms[5] = this.group_execute; cbPerms[6] = this.other_read; cbPerms[7] = this.other_write; cbPerms[8] = this.other_execute;
}


The following code segment handles the modal mode for our permissions form.

public string ShowModal(SortedList remoteFiles) { string retVal = ""; ParsePermissions(remoteFiles); if (this.ShowDialog() == DialogResult.OK) { retVal = textBox_permissonMode.Text.Trim(); } return retVal; }
private void buttonApply_Click(object sender, System.EventArgs e) { this.Close(); }
private void buttonCancel_Click(object sender, System.EventArgs e) { this.Close(); }


The ParsePermissions method does all the work converting the existing file permissions to use with our CheckBox control array. Ensure that each checkbox has its Tag property assigned the values shown in the comment.

private void ParsePermissions(SortedList remoteFiles) {
   /* We'll use the following CheckBox.Tag values to calc permissions
    * 1st Triplet: R=400, W=200, X=100
    * 2nd Triplet: R= 40, W= 20, X= 10
    * 3rd Triplet: R=  4, W=  2, X=  1
    * If more than one file is selected, set checkbox and gray out.
    */
   int counter = 0;
   int newPerm = 0;
   IEnumerator erf = remoteFiles.GetEnumerator();
   foreach (DictionaryEntry dPerms in remoteFiles) {
      counter++;
      string file = dPerms.Key.ToString();
      string perm = dPerms.Value.ToString();
      for (int i = 0; i < 9; i++) {
         if (perm.Substring(i, 1).ToLower() != "-") {
            if (counter > 1) {
               cbPerms[i].ThreeState = true;
               cbPerms[i].CheckState = CheckState.Indeterminate;
            }else{
               newPerm += Convert.ToInt16(cbPerms[i].Tag);
            }
            cbPerms[i].Checked = true;
         }else{
            if (counter > 1) {
               cbPerms[i].ThreeState = true;
               cbPerms[i].CheckState = CheckState.Indeterminate;
            }
            cbPerms[i].Checked = false;
         }
      }
   }
   textBox_permissonMode.Text = newPerm.ToString();
}


You will need to change the Click Event delegate for each CheckBox to use the following event handler. You do this by changing the delegates within the region named Windows Form Designer generated code manually.

// CODE REMOVED FOR CLARITY
// change each checkbox click event handler this.owner_read.Click += new System.EventHandler(this.Permissions_Click);
// CODE REMOVED FOR CLARITY
private void Permissions_Click(object sender, System.EventArgs e) { CheckBox cb = (CheckBox) sender; int c = Convert.ToInt16(cb.Tag); int cp = Convert.ToInt16(textBox_permissonMode.Text); switch (cb.CheckState) { case CheckState.Checked: cp += c; break; case CheckState.Unchecked: cp -= c; break; case CheckState.Indeterminate: break; } textBox_permissonMode.Text = cp.ToString(); }


The Permissions_Click event handler simply increments or decrements the permission mode textbox value by the checkbox tag value depending on whether the checkbox is checked or un-checked. It is the value of the permission mode textbox that is used by the IssueCommand method in the permissions option event handler in FormMain.cs.

Compile and run the project, then connect to a Unix server. Select one or more files in the remote files list view and right-click to display the popup menu. Select the permissions option to display the permissions form. When you click Accept, your permission settings are applied to the selected files.

Conclusion

As you can see from the status window, we issue the chmod command with the permissions we selected on the permissions form.

The original example application is provided in the free evaluation version of Secure FTP Factory for .NET.


Page 1  Page 2  Page 3