Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Method that uploads sample to ftp
- /// </summary>
- private void UploadSample()
- {
- String id = Request.QueryString["ID"];
- String path = Server.MapPath("~/temp/");
- String filename = Path.GetFileName(fuSample.PostedFile.FileName);
- try
- {
- if (
- fuSample.PostedFile.ContentType == "application/pdf"
- )
- {
- fuSample.PostedFile.SaveAs(path + fuSample.FileName);
- path += fuSample.FileName;
- String ftpServer = "ftp://130.238.174.237:2121";
- String userName = "ftpuser";
- String password = "KHR3ENJjMh";
- String uri = "ftp://130.238.174.237:2121/" + id;
- if (!DirectoryExists(uri + "/", userName, password))
- {
- // Mappen inte finns
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(uri));
- request.Method = WebRequestMethods.Ftp.MakeDirectory;
- request.Credentials = new NetworkCredential(userName, password);
- using (var resp = (FtpWebResponse)request.GetResponse())
- {
- WebClient client = new WebClient();
- client.Credentials = new NetworkCredential(userName, password);
- client.UploadFile(ftpServer + "/" + id + "/" + new FileInfo(path).Name, "STOR", path);
- backEnd.InsertSampleToDb(fuSample.FileName, id);
- resp.Close();
- }
- }
- else
- {
- // Mappen finns redan
- WebClient client = new WebClient();
- client.Credentials = new NetworkCredential(userName, password);
- client.UploadFile(uri + "/" + new FileInfo(path).Name, "STOR", path);
- backEnd.InsertSampleToDb(fuSample.FileName, id);
- }
- if (File.Exists(path))
- {
- File.Delete(path);
- }
- }
- else
- {
- lblFeedback.Text = "Ej tillåten filtyp";
- }
- }
- catch (Exception ex)
- {
- lblFeedback.Text = "Fel vid uppladdning";
- }
- }
Add Comment
Please, Sign In to add comment