title: ftp image upload to image folder only works on local host, gives error during live test
body: <p>I'm new to FTP and asp.net my code works only during local host test however during live test on go-daddy i get error. any help would be great thank you.</p>
  
  <p>I'm currently hosting 2 web site all the pages and code is in AMUS folder</p>
  
  <pre><code> Unable to connect to the remote server
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
  Exception Details: System.Net.WebException: Unable to connect to the remote server
  
  Source Error:
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Stack Trace:
  
  
  [WebException: Unable to connect to the remote server]
     System.Net.FtpWebRequest.GetRequestStream() +839
     DBMiddleTier.addImageFTP(FileUpload file) +360
     Admin_CrudOperation.imgAddProduct_Click(Object sender, ImageClickEventArgs e) +96
     System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +115
     System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +120
     System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
     System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
     System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
  </code></pre>
  
  <p>My code</p>
  
  <pre><code> //method to add image ftp
      public string addImageFTP(FileUpload file)
      {
          string filename = Path.GetFileName(file.FileName);
          Bitmap src = Bitmap.FromStream(file.PostedFile.InputStream) as Bitmap;
          Bitmap result = new Bitmap(src, 300, 300);
          string saveName = savePath + filename;
          result.Save(saveName, ImageFormat.Jpeg);
          System.Net.FtpWebRequest request = System.Net.WebRequest.Create("ftp://***.***.***.*/AMUS/images/" + filename) as System.Net.FtpWebRequest;
          //this example assumes the FTP site uses anoymous login on
          //NetWorkCredentials provides credentials for  password-based authentication such as digest, basic, NTLM
          request.Credentials = new System.Net.NetworkCredential("Username", "Password");
  
          //Copy the contents of the file to the request stream
          byte[] fileContents = null;
          if (file.HasFile)
          {
              //fileContents = FileUploadControl.FileBytes;
              fileContents = File.ReadAllBytes(saveName);
  
          }
          else
          {
              string res = "you need to provide a file";
              return res;
          }
          request.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
          request.ContentLength = fileContents.Length;
          //GetReequestStream: retrieves the stream used to upload data to an FTP server.
          Stream requestStream = request.GetRequestStream();
          requestStream.Write(fileContents, 0, fileContents.Length);
          requestStream.Close();
          return "Successful Upload";
      }
  </code></pre>