WinSCP .NET程序集:在哪里定义代理? [英] WinSCP .NET assembly: Where to define proxy?

查看:662
本文介绍了WinSCP .NET程序集:在哪里定义代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过使用WinSCP GUI来定义代理服务器。如果我这样做,我可以连接到远程主机。但在代码中,我没有找到一种方法来为WinSCP声明代理服务器。

I am able to define the proxy server by using the WinSCP GUI. If I do this I am able to connect to a remote host. But in code I don't find a way to declare the proxy server for WinSCP.

在这种情况下,我收到

In this case I receive


远程服务器返回错误(407)需要代理身份验证。

Remote server returned an error (407) Proxy authentication required.

我的代码:

SessionOptions sessionOptions = new SessionOptions
   {
       Protocol = protocol,
       HostName = hostname,
       UserName = user,
       Password = pass,
       PortNumber = portnumber
   };

using (Session session = new Session())
{
    session.ExecutablePath = @"C:\Program Files (x86)\WinSCP\WinSCP.exe";
    session.Open(sessionOptions);

    TransferOptions options = new TransferOptions();
    options.FileMask = mask;


    SynchronizationResult synchronizationResult;
    synchronizationResult =
        session.SynchronizeDirectories(mode, local, path, deletefiles, options: options);

    synchronizationResult.Check();
}


推荐答案

使用 SessionOptions.AddRawSettings 可配置适合您的原始会话设置

Use the SessionOptions.AddRawSettings to configure raw session settings appropriate for your kind of proxy.

例如:

For example:

sessionOptions.AddRawSettings("ProxyMethod", "3");
sessionOptions.AddRawSettings("ProxyHost", "proxy");

查看原始会话设置

虽然更简单的方法是在WinSCP GUI中配置代理并将其设置为为您生成代码模板

Though a way easier is to configure the proxy in WinSCP GUI and have it generate a code template for you.

这篇关于WinSCP .NET程序集:在哪里定义代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆