WinSCP .NET assembly: Where to define proxy?

≡放荡痞女 提交于 2019-11-30 15:08:25

问题


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

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

My code:

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

回答1:


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");

See a full list of raw sessions settings.


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



来源:https://stackoverflow.com/questions/13375300/winscp-net-assembly-where-to-define-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!