3

I want to ask how can I remotely delete a file using sftp I have tried using SharpSSH but it doesn't work, I got SftpException

i added this code first in the sftp.cs first

    public void Delete(string path)
    {
        SftpChannel.rm(path);
    }

then i typed this in the program

Sftp ftp = new Sftp("ip address", "username", "password"); ftp.Connect(); ftp.Delete("path");

Thanks, The problem was solved the problem was I forgot to put a "/" in front of the path, so it fails

User2012384
  • 4,769
  • 16
  • 70
  • 106
  • 1
    It would be better to show us the code thats throwing an exception so we can help fix it. – Bali C Apr 16 '12 at 15:58
  • SharpSSH *does* work. Is it possible that the code you wrote to use SharpSSH is in error? – Jim Mischel Apr 16 '12 at 16:10
  • I'd agree with @Jim, SharpSSH does work for most purposes. I've done some small bit of support. Which version are you using? What is the code you're using? The exception handling in the code is pretty bad... truth be told, I've started using SSHNet on CodePlex when I need SSH. – MattGWagner Apr 17 '12 at 01:08

1 Answers1

11

I use Renci.SshNet for my SFTP duties. It works really well for me. Here's an example of what you're trying to do:

using Renci.SshNet;
using Renci.SshNet.Sftp;

public void DeleteFile(string server, int port, string username, string password, string sftpPath)
{
    using (SftpClient sftpClient = new SftpClient(server, port, username, password))
    {
        sftpClient.Connect();
        sftpClient.DeleteFile(sftpPath);
        sftpClient.Disconnect();
    }
}
dtown123
  • 271
  • 2
  • 6