問題描述
我可以使用 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.
在這種情況下我收到
遠程服務器返回錯誤 (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)WinSCPWinSCP.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.
例如:
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 程序集:在哪里定義代理?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!