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

jamesdean666Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jamesdean666Author Commented:
Yahtzeeeeeeee.... Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.