1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace SSH
{
class droit
{
public static void Main(string hostname, string name, string pass)
{
// Important: It is helpful to send the contents of the
// ssh.LastErrorText property when requesting support.
Chilkat.Ssh ssh = new Chilkat.Ssh();
// Any string automatically begins a fully-functional 30-day trial.
bool success;
success = ssh.UnlockComponent("Anything for 30-day trial");
if (success != true)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
// Connect to an SSH server:
success = ssh.Connect(hostname,22);
if (success != true)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
// Wait a max of 5 seconds when reading responses..
ssh.IdleTimeoutMs = 5000;
// Authenticate using login/password:
success = ssh.AuthenticatePw(name, pass);
if (success != true)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
// Open a session channel. (It is possible to have multiple
// session channels open simultaneously.)
int channelNum;
channelNum = ssh.OpenSessionChannel();
if (channelNum < 0)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
// changer les droit d'un repertoir
success = ssh.SendReqExec(channelNum, "chmod 600 /home/utilisateur/.ssh/authorized_keys");
if (success != true)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
int n;
int pollTimeoutMs;
pollTimeoutMs = 2000;
n = ssh.ChannelReadAndPoll(channelNum, pollTimeoutMs);
if (n < 0)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
// Close the channel:
success = ssh.ChannelSendClose(channelNum);
if (success != true)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
success = ssh.ChannelReceiveToClose(channelNum);
if (success != true)
{
MessageBox.Show(ssh.LastErrorText);
return;
}
// Disconnect
//ssh.Disconnect();
}
}
} |
Partager