How to upload files to ftp using asp.net and C#?
<p>I tried to upload image through ftp using asp.net &amp; c# but it doesn't work.
Please guide me to solve the issue asap.</p>

<pre><code>try
        {
            //host name         
            //string ftphost = "fubar.walnut.com";
            string ftphost = "fubar.walnut.com";
            //file path         
            string ftpfilepath = "/ProductImages/" + FileUpload1.FileName;
            string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
            //create ftp request         
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            //userid and password for the ftp server         
            ftp.Credentials = new NetworkCredential("username", "password");
            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.UsePassive = true;
            //select method as upload file (STOR command)         
            ftp.Method = WebRequestMethods.Ftp.UploadFile;
            FileStream stream = File.OpenRead(Server.MapPath("~/" + FileUpload1.FileName));
            byte[] buffer1 = new byte[stream.Length];
            stream.Read(buffer1, 0, buffer1.Length);
            stream.Close();
            //get request stream         
            Stream ftpstream = ftp.GetRequestStream();
            ftpstream.Write(buffer1, 0, buffer1.Length);
            ftpstream.Close();

            ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Image uploaded successfully.'); window.location.href = 'UploadZipXML.aspx?ProductIsOpen=true';", true);
            return;
        }
        catch (Exception ex)
        {
            string excp = ex.Message;
            ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Image not uploaded successfully." + excp + "')", true);
            return;
        }
</code></pre>
