How to delete a file from a SFTP server using Tamir Gal's SharpSSH? I have been able to accomplish other functionality but deletion.
delete( s , filename ) deletes the specified file from the current folder on the SFTP or FTP server associated with s .
To delete a file on the server, type "rm" and then the filename. Syntax: psftp> rm filename.
You can delete multiple files also using del. file1.sh, file2.sh, file3.sh, file4.sh, file5.sh will be deleted in /home/user1.
The SshExec class didn't work for me, but a little Reflection magic worked:
var prop = sftp.GetType().GetProperty("SftpChannel", BindingFlags.NonPublic | BindingFlags.Instance);
var methodInfo = prop.GetGetMethod(true);
var sftpChannel = methodInfo.Invoke(sftp, null);
((ChannelSftp) sftpChannel).rm(ftpPath);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With