• Advertisement
Sign in to follow this  

upload image to ftp server C#

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

id like to convert to png and upload data i have in a "Image" type to a ftp server.... how would i do that? im using C# .NET 3.5 EDIT:: i guess something like this... but it doesnt work...
      static void UploadImage(string filename, Image image)
        {
            
            try
            {
                FileInfo fileInf = new FileInfo(filename);
                string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
                FtpWebRequest reqFTP;

                // Create FtpWebRequest object from the Uri provided
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(
                        "ftp://" + ftpServerIP + "/" + fileInf.Name));

                // Provide the WebPermission Credintials
                reqFTP.Credentials = new NetworkCredential(ftpUserID, 
                                                         ftpPassword);

                // By default KeepAlive is true, where the control connection is 
                // not closed after a command is executed.
                reqFTP.KeepAlive = false;

                // Specify the command to be executed.
                reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

                // Specify the data transfer type.
                reqFTP.UseBinary = true; ???

                // Notify the server about the size of the uploaded file
                //reqFTP.ContentLength = fileInf.Length; ???

                using (Stream strm = reqFTP.GetRequestStream())
                {                
                    image.Save(strm, ImageFormat.Png);
                    strm.Close();
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "Upload Error");
            }
                     
        }


[Edited by - Dragon_Strike on March 20, 2008 3:06:55 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement