试图从SFTP服务器下载文件,但我收到此错误“无法找到路径的一部分”

时间:2018-03-21 06:57:22

标签: c# sftp

class program {
    static void Main(string[] args) {
        const string host = "XXXX";
        const string username = "XXXX";
        const string password = "XXXX";
        const string workingdirectory = "/home/DRuser/Digital 
        River / Inbound / ";
        const string remotefile = "/home/DRuser/Digital 
        River / Inbound / Analysis
        for Production Fix Substring.csv ";
        const int port = XX;

        Console.WriteLine("Creating Client and Connecting");
        using(var client = new SftpClient(host, port, username, password)) {
            client.Connect();
            Console.WriteLine("Connected to host");

            client.ChangeDirectory(workingdirectory);
            Console.WriteLine("Changed directory to {0}", workingdirectory);

            var listDirectory = client.ListDirectory(workingdirectory);
            Console.WriteLine("Listing directory:");
            foreach(var fi in listDirectory) {
                Console.WriteLine(" - " + fi.Name);
            }
            using(var file = File.OpenWrite(remotesite)) //download file from sftp to local
            {
                client.DownloadFile(remotefile, file);
                Console.WriteLine("Successfully Downloaded");
            }
            client.Disconnect();
        }
    }
}

我成功连接到sftp服务器并循环遍历所有 相应目录中的文件,但当我尝试 下载它我得到这个错误

  

无法找到路径'C:\ home \ DRuser \ Digital River \ Inbound \'的一部分。   我在使用(var file = File.OpenWrite(remotesite))代码行时遇到此错误。

我该如何解决这个问题?

0 个答案:

没有答案