Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinSCP .NET assembly: Where to define proxy?

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();
}
like image 575
deyaert Avatar asked Nov 14 '12 08:11

deyaert


People also ask

What is WinSCP .NET assembly?

The WinSCP . NET assembly winscpnet. dll is a . NET wrapper around WinSCP's scripting interface that allows your code to connect to a remote machine and manipulate remote files over SFTP , FTP , WebDAV , S3 and SCP sessions from . NET languages, such as C#, VB.NET, and others, or from environments supporting .


1 Answers

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.

like image 149
Martin Prikryl Avatar answered Oct 14 '22 10:10

Martin Prikryl