Use Windows credentials to connect to FTP in .NET.

The issue is related to an FTP connection using Windows credentials , but the discussion in this section went in a different direction.

CredentialCache.DefaultCredentials does not work with FTP. Is there a way to use a Windows user account as credentials for an FTP connection in C #?

If the FTP server can accept Kerberos tickets for authentication, how can you send it using the FtpWebRequest class?

+4
source share
2 answers

The following are three ways to log in to FTP, but they still require a username for a username or password:

System.Net.FtpWebRequest f = System.Net.FtpWebRequest.Create(new Uri("ftp://somewhere.com")) as System.Net.FtpWebRequest; if (f != null) { f.Credentials = new System.Net.NetworkCredential("username", "password", "domain"); f.Credentials = new System.Net.NetworkCredential("username", "password"); f.Credentials = new System.Net.NetworkCredential(System.Security.Principal.WindowsIdentity.GetCurrent().Name, "password"); } 

The latter accepts a Windows username, but still requires some way to get the password from the user.

0
source

I'm not sure what credentials you are talking about.

If you are talking about an FTP username and password, follow these steps:

 R.Credentials = new NetworkCredential(UserName, Password); 

Gotta do the trick.

If you ask about the proxy credentials that are used on Windows to go through the proxy server in the same way that Explorer or Firefox pass the proxy server, then:

 R.Proxy = new WebProxy(); 

Will do the trick.

0
source

Source: https://habr.com/ru/post/1341821/


All Articles