protected void UploadButton_Click(object sender, EventArgs e) { if (FileUploadControl.HasFile) { try { if (FileUploadControl.PostedFile.ContentType == "image/jpeg") { if (FileUploadControl.PostedFile.ContentLength < 5242881) { string filename = Path.GetFileName(FileUploadControl.FileName); Stream image; string target = "1.jpg"; FtpWebRequest req = (FtpWebRequest)WebRequest.Create("ftp://ftppath" + target); req.UseBinary = true; req.Method = WebRequestMethods.Ftp.UploadFile; req.Credentials = new NetworkCredential("ftpUname", "ftpPass"); byte[] fileData = File.ReadAllBytes(filename); req.ContentLength = fileData.Length; Stream reqStream = req.GetRequestStream(); reqStream.Write(fileData, 0, fileData.Length); reqStream.Close(); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch (Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)