gpt4 book ai didi

c# - 使用C#程序通过SFTP远程删除文件

转载 作者:太空宇宙 更新时间:2023-11-03 20:26:53 24 4
gpt4 key购买 nike

我想问一下如何使用sftp远程删除文件我试过使用 SharpSSH 但它不起作用,我得到了 SftpException

我首先在 sftp.cs 中添加了这段代码

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

然后我在程序中输入了这个

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

谢谢,问题解决了问题是忘记在路径前加上“/”,所以失败了

最佳答案

我使用 Renci.SshNet为了我的 SFTP 职责。它对我来说真的很好用。这是您尝试执行的操作的示例:

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();
}
}

关于c# - 使用C#程序通过SFTP远程删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10177538/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com