CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Question Annoying FTP exception

    I have an FTP upload:

    Code:
                    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(localFilenames[0]);
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    fs.Close();
                    ftpstream = ftp.GetRequestStream();
                    ftpstream.Write(buffer, 0, buffer.Length);
    I get an error (attachment) when I try to run the code with the following ftp path.
    ftp://penappit01/usr2/unisex/modulli...76829.fejl.xml
    It's driving me nuts - maybe I've just looked at it too long, but if someone out there can see what's wrong I'd appreciate it.
    Attached Images Attached Images

  2. #2
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Annoying FTP exception

    I checked the WebRequest.Create() method with that URI on my on machine and it worked fine... weird! That 'The handle is invalid' message seems kind of strange. Have you inspected the InnerException property to see what that's all about?
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Annoying FTP exception

    Turn the Keep Alive off.

    Code:
    FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
    ftp.KeepAlive = false;
    According to FtpWebRequest.KeepAlive property in msdn...
    Gets or sets a Boolean value that specifies whether the control connection to the FTP server is closed after the request completes.
    What I believe is going on is that the ftp server keeps the connection alive after the ftp variable has gone out of scope. The error is because the 'ftp' instance isn't around anymore and the ftp service tries to ping the instance (as part of its keep alive functionality).

  4. #4
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: Annoying FTP exception

    It is indeed weird. The only thing I get in the exception is that "the handle is invald" whatever handle that may be.

    I get the exception in the Create() call, so disabling KeepAlive won't change anything as the exception is thrown in the previous line.

    The really weird thing is, that this has worked previously. I'm starting to wonder if it really is some (sub) DLL that it can't load, and thus can't get a handle to...

  5. #5
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Re: Annoying FTP exception

    Hm...apparently it helped to re-add System.Net, kill my resharper cache and then recompile everything.

    Sorry for disturbing the peace on the forum for this. Now all I have to deal with is that it whines about my filename not being correct. For some reason it now gives me a 553 File name not allowed :-/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured