sftp连接问题c#

时间:2016-12-10 14:12:33

标签: c# winforms ssh sftp

当我尝试连接到sftp时使用Renci.SshNet我有这样的错误:

'client2.ProtocolVersion' threw an exception of type 'Renci.SshNet.Common.SshConnectionException'
'client2.WorkingDirectory' threw an exception of type 'Renci.SshNet.Common.SshConnectionException'

我该如何解决?

public void Upoad3(string filenames)
{
    try
    {
        const string host = "ftp";
        const string login = "login";
        const string pass = "pass";
        const string workingdirectory = "/w53850/";
        SftpClient client2 = new SftpClient(host, login, pass);
        client2.Connect();
        //client2.ChangeDirectory(workingdirectory);
        FileStream files = File.OpenRead(filenames);
        using (var fileStream = new FileStream(filenames, FileMode.Open))
        {
            client2.BufferSize = 4 * 1024;
            client2.UploadFile(fileStream, filenames);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

0 个答案:

没有答案