Connect to FTPS with proxy in C#

前端 未结 1 2020
鱼传尺愫
鱼传尺愫 2020-12-18 09:49

My below code works perfectly fine in my computer without proxy. But in client server they need to add proxy to the FTP client (FileZilla) to be able to access the FTP. But

1条回答
  •  攒了一身酷
    2020-12-18 10:14

    .NET framework indeed does not support TLS/SSL connections over proxy.

    You have to use a 3rd party FTP library.

    Also note that your code is not using "implicit" FTPS. It's using "explicit" FTPS. Implicit FTPS is not supported by .NET framework either.


    For example with WinSCP .NET assembly, you can use:

    // Setup session options
    SessionOptions sessionOptions = new SessionOptions
    {
        Protocol = Protocol.Ftp,
        HostName = "example.com",
        UserName = "user",
        Password = "mypassword",
        FtpSecure = FtpSecure.Explicit, // Or .Implicit
    };
    
    // Configure proxy
    sessionOptions.AddRawSettings("ProxyMethod", "3");
    sessionOptions.AddRawSettings("ProxyHost", "proxy");
    
    using (Session session = new Session())
    {
        // Connect
        session.Open(sessionOptions);
    
        var listing = session.ListDirectory(path);
    }
    

    For the options for SessionOptions.AddRawSettings, see raw settings.

    (I'm the author of WinSCP)

    0 讨论(0)
提交回复
热议问题