I am trying to connect to an FTP server to upload a file. I am getting the ”
Unable to connect” error. If I use command line and open an FTP connection, I am able to connect. Not sure why I get error when connecting programatically. Any help will surely be appreciated.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://1.23.84.2");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("user","password");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(path);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}",
response.StatusDescription);
response.Close();
So after a few hours of trouble shooting, It was McAfee blocking the ftp port. had to temporarily disable the services on a local machine.