SendCommand on SFTP

0

We have a site that just switched to SFTP. It has a custom integration which used SendCommand.  This method does not exist on the SFTP component. How can I issue commands on SFTP?

edited 12/3/2017 5:07:02 AM
asked 3/29/2017 11:01:52 PM
add a comment

1 Answers

0

Hi,

Is this what you are looking for? http://www.componentpro.com/doc/sftp/execute-a-command.htm

using System;

using System.Text;
using ComponentPro.IO;
using ComponentPro.Net;

...

// Create a new Sftp instance.
Sftp client = new Sftp();

// Connect to the SFTP server.
client.Connect(serverName);

SecureShellChannel sshChannel = client.Connection.OpenSession();

// Authenticate.
client.Authenticate(userName, password);

// List directory '/usr/share/doc'
sshChannel.RequestExec("ls /usr/share/doc");

// Process the command response
StringBuilder response = new StringBuilder();
byte[] buffer = new byte[4096];
while (true)
{
    int n = sshChannel.Receive(buffer, 0, buffer.Length);
    if (n == 0)
    {
        sshChannel.Close();
        break;
    }

    response.Append(Encoding.Default.GetString(buffer, 0, n));
}

// Show the directory content
Console.WriteLine("Directory content: " + response.ToString());

// Disconnect. 

client.Disconnect();

 
answered 11/16/2017 12:41:37 AM
add a comment

Your Answer

Not the answer you're looking for? Browse other questions tagged ftp sftp or ask your own question.