• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1921
  • Last Modified:

C# ASP.NET FTP - System.IO.FileNotFoundException: Could not find file 'C:\Test6.doc'.

I  am using the attached code to FTP files to an FTP Site.  It works great on my local development box, but when I upload the files to the server - it throws this error:

System.IO.FileNotFoundException: Could not find file 'C:\Test6.doc'.

I believe it's because it's looking for the file in that path, which is not on the server, but on my local pc..

Any Ideas?




string ftphost = "ftp.xxxx.net";
                string ftpfullpath = "ftp://" + ftphost;
                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath + @"/" + ftpfilepath);

                ftp.Credentials = new NetworkCredential("AAA", "BBB");

                ftp.KeepAlive = true;
                ftp.UseBinary = true;

                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileUpload fileUploadObject = (FileUpload)Session["FileUploadObject"];
                ATNFile aFile = new ATNFile();
                aFile.Name = fileUploadObject.PostedFile.FileName;

                FileStream fs = File.OpenRead(aFile.Name);

                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                fs.Close();
                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
                ftpstream.Close();

Open in new window

0
jamesdean666
Asked:
jamesdean666
  • 2
  • 2
1 Solution
 
SriVaddadiCommented:
Why is it looking for that file? Did you give that path anywhere? if so where did you give it?
0
 
jamesdean666Author Commented:
It is reading the path here:

aFile.Name = fileUploadObject.PostedFile.FileName;

this is returning what is in the fileupload control on my GUI

That is the issue, it is reading my local path/file name, and it obviously doesn't exist on the server that the site is hosted on - hence the error.. how do you handle this..?

If you can't tell, I'm a newbie.. :)
0
 
SriVaddadiCommented:
Well, looks like you are storing the file upload control into session.

Once the file is uploaded, you have to save the file to the server at a temp location and then use that file to ftp.

Do not use the file upload control directly from session.

Check this example for better understanding.

http://asp.net-tutorials.com/controls/file-upload-control/
0
 
jamesdean666Author Commented:
Yahtzeeeeeeee.... Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now