Get my application to be allowed access through firewall using c#

前端 未结 4 1834
失恋的感觉
失恋的感觉 2021-01-24 09:10

i am trying to get my application to be allowed through firewall, as I have to do ftp in active and passive mode is not an option as servers are not configured for that. so i tr

相关标签:
4条回答
  • 2021-01-24 09:28

    For running as a different user: Run Code as a different user (C#)

    As for getting through the firewall, have you talked to the person/group responsible for the firewall security? They may have some rules in place that you could use.

    0 讨论(0)
  • 2021-01-24 09:33

    i have observed that if i change the order of ftp download statements to following windows dialog appears asking that do you want to allow this program access through firewall; if i click allow access the code works perfectly.

    requestDownload = (FtpWebRequest)WebRequest.Create(uri);
                                requestDownload.UsePassive = false;
                                requestDownload.KeepAlive = false;
                                requestDownload.UseBinary = true;
                                requestDownload.Method = WebRequestMethods.Ftp.DownloadFile;
    
    
                                requestDownload.Credentials = new NetworkCredential(ftpInfoDownload[3], ftpInfoDownload[4]);
    
                                responseDownload = (FtpWebResponse)requestDownload.GetResponse();
                                Stream ftpStream = responseDownload.GetResponseStream();
    
    0 讨论(0)
  • 2021-01-24 09:37

    Try opening the FTP ports in the firewall -- ports 20 and 21 -- and see if that solves your issue.

    0 讨论(0)
  • 2021-01-24 09:43

    Firewall management is a system level security feature and has to be done outside of user mode application code. Configuration must be done by an administrator.

    It is bad practice to write the code that you wrote and assume that your application will be run as administrator. Even if it is run by an administrator, you now have an application that "does FTP stuff" and "does firewall stuff". No application has ever been written like this.

    You can write code that interacts with the system firewall, and that code must be run with elevated permissions. Typically such "helper applications" are never even created however as Windows (and every other OS) has all the necessary management tools shipped with the OS (i.e. wf.msc).

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