Reputation: 399
I want to access/ read text file from a ftp site but I encountered an error say's:
Unable to cast object of type 'System.Net.HttpWebRequest' to type 'System.Net.FtpWebRequest'.
Here's my code in C#:
string username = "username";
string password = "password";
FtpWebRequest tmpReq = (FtpWebRequest)FtpWebRequest.CreateDefault(new Uri("http://crmweb.com.ph/ftp/ftpuser1/User/tbl_users.csv"));
tmpReq.Credentials = new System.Net.NetworkCredential(username, password);
Upvotes: 1
Views: 2056
Reputation: 23935
There are 2 possible errors in your code:
1.:
If the address and protocol (http) are correct you have to use HttpWebRequest
:
var tmpReq = HttpWebRequest.Create(new Uri("http://crmweb.com.ph/ftp/ftpuser1/User/tbl_users.csv"));
2.: If you want to open an FTP connection, you have to specify a valid ftp-address (use ftp://)
var ftpReq = FtpWebRequest.Create(new Uri("ftp://bulk.resource.org"))
Upvotes: 2