0

I am trying to connect to a corporate ftp server via code (C#/VB). It has been set up to run in a browser using SolarWinds Serv-U software so that users can access it via a browser. The address is in the form:

https://ftp.example.com

From here they are presented with a login form (part of Serv-U) in which they enter their u/p and log in.

I have been trying to use HttpWebRequest class to log in, but each time I get an '401 Unauthorised - not logged in' error. In the web request I set the credentials:

Dim loginUri = New Uri("https://ftp.example.com")
Dim loginRequest As HttpWebRequest = DirectCast(WebRequest.Create(loginUri), HttpWebRequest)

    With loginRequest

        .Accept = "*/*"
        .ContentType = "application/x-www-form-urlencoded"
        .CookieContainer = New CookieContainer()
        .Credentials = New NetworkCredential("user", "pass")
        .Method = WebRequestMethods.Http.Get

    End With

Dim loginResponse As HttpWebResponse = loginRequest.GetResponse()

I'm not even sure if this approach is possible; there are quite a number of cookies set by the browser during the login process which is not a desirable thing to replicate in code.

I've done a fair bit of searching on the subject and haven't found any definitive answers. Should I just push back on the sysadmin to set up a proper ftp server over SSL? It is a requirement that we use :443 as many firewalls block 21 (& 22).

Thanks - Z

zetetic
  • 73
  • 1
  • 6
  • http://stackoverflow.com/questions/13296765/uploading-file-on-secured-ftp-over-https-protocol-c-sharp?rq=1 – Bolu Apr 28 '15 at 09:55
  • You should really use example.com instead of xxx.com as an example url. – sloth Apr 28 '15 at 10:28
  • @Bolu That question is for FTP over TLS/SSL (despite the question title). While this seems to be about HTTP (not about FTP, despite the question title). – Martin Prikryl Apr 28 '15 at 11:25
  • 1
    Sure, using standard FTP protocol would be a way to go, instead of trying to implement their proprietary "web" protocol. Or at least ask Serv-U vendor for the protocol specification. We are not here to reverse-engineer that. – Martin Prikryl Apr 28 '15 at 11:29
  • Thanks Martin, concurs with what I was thinking. – zetetic Apr 28 '15 at 13:00

0 Answers0