Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FTPWebRequest - How to connect without ftp:// in host address?

Tags:

c#

ftp

Im creating a module for a scheduled system that needs to execute FTP commands.

The ftp host we are trying to connect to is simply an IP address. i.e below

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("10.1.1.1");

When trying to execute this, it complains that it cant define the type of connection, fine when prefixed with ftp:// but then it doesnt resolve as that host does not exist. I am unable to change to host header for the host.

Is there some way to define the Uri as an FTP address without including it in the address? Seems a handy enum would be ideal to identify it as an ftp or http etc.

Or is there another way to connect to an FTP site that I havent found yet?

TIA

like image 711
Chris Avatar asked Dec 21 '25 07:12

Chris


1 Answers

Why can you not simply add ftp:// to the address?

FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://10.1.1.1");

WebRequest will need the protocol information in order to know what kind of WebRequest implementation to create (WebRequest is an abstract class that is implemented by HttpWebRequest and FtpWebRequest).

like image 59
Fredrik Mörk Avatar answered Dec 23 '25 20:12

Fredrik Mörk