Chris
Chris

Reputation: 165

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

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

Upvotes: 3

Views: 3530

Answers (1)

Fredrik Mörk
Fredrik Mörk

Reputation: 158349

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).

Upvotes: 5

Related Questions