首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误: c#中没有这样的文件‘Renci.SshNet.Common.SftpPathNotFoundException:’

错误: c#中没有这样的文件‘Renci.SshNet.Common.SftpPathNotFoundException:’
EN

Stack Overflow用户
提问于 2019-02-06 21:32:57
回答 1查看 5.2K关注 0票数 0

所以我有这样的代码:

代码语言:javascript
运行
复制
public static void UploadSFTPFile(string host, string username,
    string password, string sourcefile, string destinationpath, int port)
    {
        string Ip = "";
        String strHostName = string.Empty;
        IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
        IPAddress[] addr = ipEntry.AddressList;

        for (int i = 0; i < addr.Length; i++)
        {
            Ip = (addr[i].ToString());
        }
        using (SftpClient client = new SftpClient(host, port, username, password))
        {
            client.Connect();
            client.ChangeDirectory(destinationpath);
            using (FileStream fs = new FileStream(sourcefile, FileMode.Open))
            {
                client.BufferSize = 4 * 1024;
                client.UploadFile(fs, Path.GetFileName(sourcefile));

            }
            client.WriteAllText("C:/Users/Public/Documents/192.168.0.112.json", "jeff");
        }
    }

我使用此方法在我的sftp服务器中上传文件。这很好用,但我也尝试在文件中写一些东西:

代码语言:javascript
运行
复制
 client.WriteAllText("C:/Users/Public/Documents/Test.json", "jeff");

这就是我处理错误消息的地方:

代码语言:javascript
运行
复制
Renci.SshNet.Common.SftpPathNotFoundException: 'No such file'

我做错了什么?这是文件所在的位置,我是管理员。

EN

Stack Overflow用户

发布于 2019-02-06 21:37:51

在Windows中,文件夹分隔符是反斜杠"\"而不是斜杠"/"

而是使用

代码语言:javascript
运行
复制
client.WriteAllText(@"C:\Users\Public\Documents\Test.json", "jeff");
//                  ^---------------------- Notice the @ that will automatically escape the \
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54554857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档