title: Unable to connect to server when uploading file using FTP
body: <p>I am working with mvc 4.5 trying to upload an image using FTP.</p>
  
  <p>My code:</p>
  
  <pre><code>public virtual void Send(HttpPostedFileBase uploadfile, string fileName)
  {
      Stream streamObj = uploadfile.InputStream;
      byte[] buffer = new byte[uploadfile.ContentLength];
      streamObj.Read(buffer, 0, buffer.Length);
      streamObj.Close();
  
      string ftpurl = String.Format("{0}/{1}/{2}", _remoteHost, _foldersHost, fileName);
      var request = FtpWebRequest.Create(ftpurl) as FtpWebRequest;
  
      request.Method = WebRequestMethods.Ftp.UploadFile;
      request.UsePassive = false;
      request.Credentials = new NetworkCredential(_remoteUser, _remotePass);
      request.ContentLength = buffer.Length;
  
      var requestStream = request.GetRequestStream();
      requestStream.Write(buffer, 0, buffer.Length);
      requestStream.Close();
  
      var response = (FtpWebResponse) request.GetResponse();
  
      if (response != null)
          response.Close();
  }
  </code></pre>
  
  <p>The code is working on localhost, I am able to conect to the FTP server and upload the file, but the problem comes once the project is published. I am using SmarterASP to host the site. When I try to upload the image on production, the uploading method gives me an exception, the message says "Unable to connect to the remote server".</p>
  
  <p>Any clue or workaround?</p>
  
  <p>Exception details:</p>
  
  <p><em>System.Net.FtpWebRequest.GetRequestStream() at AgileResto.Controllers.RestaurantsController.Send(HttpPosted‌​FileBase uploadfile, String fileName) at AgileResto.Controllers.RestaurantsController.UploadFile(Int3‌​2 RestaurantList, HttpPostedFileBase file, HttpPostedFileBase file2)</em></p>