0
try
{
    FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
    ftp.Credentials = new NetworkCredential(username, Password);

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

    FileStream fs = File.OpenRead(filepath);
    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();
}
catch (Exception ex)
{
    throw ex;
}

I really have no idea what I should do now, I searched through the Internet and couldn't find a way to fix the problem.

I am using System.Net as well, so it shouldn't be a problem.

An unhandled exception of type 'System.Net.WebException' occurred in Project.exe Additional information: System Error.

Thanks for all the help!

René Vogt
  • 43,056
  • 14
  • 77
  • 99
JDoe
  • 9
  • 2
  • 1
    On which line you get the exception? Any more details? Can you add `catch (WebException wEx) { throw wEx; }` before your `catch` and see if it gives more info? *Edit: Also include wEx.InnerException if possible. – uTeisT Aug 11 '16 at 14:36
  • Full exception stack please (of the `ex`, not of the exception you re-throw). – Martin Prikryl Aug 11 '16 at 14:36
  • Have you tried writing a Global Exception Handler? Something like this: http://stackoverflow.com/questions/3133199/net-global-exception-handler-in-console-application - that'll at least give you some more information. – EJoshuaS - Stand with Ukraine Aug 11 '16 at 14:37
  • Also, right now you immediately re-throw any exception you receive, so (unless there's other error handling logic you haven't shown) *any* exception you get will be unhandled by definition - you're not handling it. Also, when re-throwing an exception you should use "throw;" rather than "throw exc;" to preserve the stack trace. – EJoshuaS - Stand with Ukraine Aug 11 '16 at 14:42
  • On a side note, you should never rethrow and execption like this since it will reset the stack trace. Instead simply write `throw;` in the catch block and .Net will rethrow the exception without wiping the stack trace. – Noémie Lord Aug 11 '16 at 14:43

0 Answers0