問(wèn)題描述
我可以使用 WinSCP GUI 定義代理服務(wù)器.如果我這樣做,我可以連接到遠(yuǎn)程主機(jī).但是在代碼中我找不到為 WinSCP 聲明代理服務(wù)器的方法.
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.
在這種情況下我收到
遠(yuǎn)程服務(wù)器返回錯(cuò)誤 (407) 需要代理身份驗(yàn)證.
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
配置適合您的代理類(lèi)型的原始會(huì)話設(shè)置.
Use the SessionOptions.AddRawSettings
to configure raw session settings appropriate for your kind of proxy.
例如:
sessionOptions.AddRawSettings("ProxyMethod", "3");
sessionOptions.AddRawSettings("ProxyHost", "proxy");
查看原始會(huì)話設(shè)置的完整列表.
雖然更簡(jiǎn)單的方法是在 WinSCP GUI 中配置代理 并擁有它為您生成代碼模板.
Though a way easier is to configure the proxy in WinSCP GUI and have it generate a code template for you.
這篇關(guān)于WinSCP .NET 程序集:在哪里定義代理?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!