Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

c# FTP ftpwebrequest URI invalid

Avatar of NJJoeG8GT
NJJoeG8GTFlag for United States of America asked on
C#
6 Comments1 Solution447 ViewsLast Modified:
i think the file name may be incorrect but i cannot tell why this throwing this exception.
any ideas?

fileName = "c:/soapmessages/OUT/" + var_yr + var_mth + var_day + "_XXXXXXX.csv";

error:
System.Net.WebException: The requested URI is invalid for this FTP command.
   at System.Net.FtpWebRequest.GetRequestStream()
   at XXXXXXXX.Program.Main(String[] args) in J:\mastersource\XXXXXX\ConsoleApplication2\Program.cs:line 179



string ftpfullpath = Path.GetFileName(ftpFile);
              FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpFile));
              ftp.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

              ftp.KeepAlive = true;
              ftp.UseBinary = true;
              ftp.Method = WebRequestMethods.Ftp.UploadFile;

              FileStream fs = File.OpenRead(fileName);
              byte[] buffer = new byte[fs.Length];
              fs.Read(buffer, 0, buffer.Length);
              fs.Close();

             [b] Stream ftpstream = ftp.GetRequestStream();      <--- line 179[/b]
              ftpstream.Write(buffer, 0, buffer.Length);
              ftpstream.Close();
ASKER CERTIFIED SOLUTION
Avatar of ktaczala
ktaczalaFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers