FtpWebRequest DeleteFile Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Waldy

    FtpWebRequest DeleteFile Problem

    Hi there,
    I have written a service in VS2005 that downloads files from
    an FTP site processes them and then deletes the files if successfully
    processed. It all works fine when run in our test lab with an FTP site that
    I setup on IIS. However, I have an issue at the customer site. Their FTP
    server is on Linux, but I presume that is not an issue. What happened the
    first time I ran it was that it deleted every other file. It just so
    happened that there were files of about 60k and files of about 600k. The
    small files were deleted, but the large ones were not. A WebException error
    occured for the second, fourth e.t.c. files. When I ran it again, only the
    larger files were left in the FTP folder, and only the first one was
    deleted. I guess it may be sone sort of timing issue..


  • Ignacio Machin ( .NET/ C# MVP )

    #2
    Re: FtpWebRequest DeleteFile Problem

    On Aug 29, 5:38 am, "Waldy" <some...@micros oft.comwrote:
    Hi there,
                  I have written a service in VS2005 that downloads files from
    an FTP site processes them and then deletes the files if successfully
    processed.  It all works fine when run in our test lab with an FTP sitethat
    I setup on IIS.  However, I have an issue at the customer site.  Their FTP
    server is on Linux, but I presume that is not an issue.  What happened the
    first time I ran it was that it deleted every other file.  It just so
    happened that there were files of about 60k and files of about 600k.  The
    small files were deleted, but the large ones were not.  A WebException error
    occured for the second, fourth e.t.c. files.  When I ran it again, onlythe
    larger files were left in the FTP folder, and only the first one was
    deleted.  I guess it may be sone sort of timing issue..
    what says the exception?
    Can you delete those files if you connect from the system ftp? maybe
    you do not have permission to delete them

    Comment

    • Goran Sliskovic

      #3
      Re: FtpWebRequest DeleteFile Problem


      "Waldy" <someone@micros oft.comwrote in message
      news:u%23TTHsbC JHA.3496@TK2MSF TNGP03.phx.gbl. ..
      Hi there,
      I have written a service in VS2005 that downloads files from
      an FTP site processes them and then deletes the files if successfully
      processed. It all works fine when run in our test lab with an FTP site
      that
      I setup on IIS. However, I have an issue at the customer site. Their FTP
      server is on Linux, but I presume that is not an issue. What happened the
      first time I ran it was that it deleted every other file. It just so
      happened that there were files of about 60k and files of about 600k. The
      small files were deleted, but the large ones were not. A WebException
      error
      occured for the second, fourth e.t.c. files. When I ran it again, only
      the
      larger files were left in the FTP folder, and only the first one was
      deleted. I guess it may be sone sort of timing issue..
      >
      >
      Can you please check exact exception? Is it maybe "bad sequence of
      commands"?

      Regards,
      Goran


      Comment

      • Waldy

        #4
        Re: FtpWebRequest DeleteFile Problem


        "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
        news:eKC3DDDDJH A.4816@TK2MSFTN GP06.phx.gbl...
        Can you please check exact exception? Is it maybe "bad sequence of
        commands"?
        Hi Goran,
        here is the error:

        Exception: System.Net.WebE xception
        Message: The remote server returned an error: (500) Syntax error, command
        unrecognized.
        Source: System
        at System.Net.FtpW ebRequest.SyncR equestCallback( Object obj)
        at System.Net.FtpW ebRequest.Reque stCallback(Obje ct obj)
        at System.Net.Comm andStream.Abort (Exception e)
        at System.Net.FtpW ebRequest.Finis hRequestStage(R equestStage stage)
        at System.Net.FtpW ebRequest.GetRe sponse()


        Comment

        • Pavel Minaev

          #5
          Re: FtpWebRequest DeleteFile Problem

          "Waldy" <someone@micros oft.comwrote in message
          news:%23PzWsXND JHA.4436@TK2MSF TNGP02.phx.gbl. ..
          >
          "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
          news:eKC3DDDDJH A.4816@TK2MSFTN GP06.phx.gbl...
          >Can you please check exact exception? Is it maybe "bad sequence of
          >commands"?
          >
          Hi Goran,
          here is the error:
          >
          Exception: System.Net.WebE xception
          Message: The remote server returned an error: (500) Syntax error, command
          unrecognized.
          Source: System
          at System.Net.FtpW ebRequest.SyncR equestCallback( Object obj)
          at System.Net.FtpW ebRequest.Reque stCallback(Obje ct obj)
          at System.Net.Comm andStream.Abort (Exception e)
          at System.Net.FtpW ebRequest.Finis hRequestStage(R equestStage stage)
          at System.Net.FtpW ebRequest.GetRe sponse()
          It might help if you use a packet sniffer to get the actual log of the FTP
          session - what commands go to the server, and what the responses to each
          are.


          Comment

          • Goran Sliskovic

            #6
            Re: FtpWebRequest DeleteFile Problem


            "Pavel Minaev" <int19h@gmail.c omwrote in message
            news:esp8HqNDJH A.4712@TK2MSFTN GP05.phx.gbl...
            "Waldy" <someone@micros oft.comwrote in message
            news:%23PzWsXND JHA.4436@TK2MSF TNGP02.phx.gbl. ..

            "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
            news:eKC3DDDDJH A.4816@TK2MSFTN GP06.phx.gbl...
            Can you please check exact exception? Is it maybe "bad sequence of
            commands"?
            Hi Goran,
            here is the error:

            Exception: System.Net.WebE xception
            Message: The remote server returned an error: (500) Syntax error,
            command
            unrecognized.
            Source: System
            at System.Net.FtpW ebRequest.SyncR equestCallback( Object obj)
            at System.Net.FtpW ebRequest.Reque stCallback(Obje ct obj)
            at System.Net.Comm andStream.Abort (Exception e)
            at System.Net.FtpW ebRequest.Finis hRequestStage(R equestStage stage)
            at System.Net.FtpW ebRequest.GetRe sponse()
            >
            It might help if you use a packet sniffer to get the actual log of the FTP
            session - what commands go to the server, and what the responses to each
            are.
            >
            >
            Yes, sniffer should reveal the problem. I had similar problem with UNIX
            based system and FTPWebRequest. FTPWebRequest is cacheing connections to FTP
            server and reuses the connection between commands. However, it resend
            USER/PASS commands even on already connected and authorized connection (and
            that is allowed according to standard) and UNIX server refuses it (it's an
            embedded system). I end up with "bad sequence of commands", which is bit
            different than what original poster gets.

            Wireshark is free and powerfull sniffer, if we see the trace I guess will
            find the problem.

            Regards,
            Goran


            Comment

            • Waldy

              #7
              Re: FtpWebRequest DeleteFile Problem

              "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
              news:O3iKGOPDJH A.484@TK2MSFTNG P05.phx.gbl...
              Yes, sniffer should reveal the problem. I had similar problem with UNIX
              based system and FTPWebRequest. FTPWebRequest is cacheing connections to
              FTP
              server and reuses the connection between commands. However, it resend
              USER/PASS commands even on already connected and authorized connection
              (and
              that is allowed according to standard) and UNIX server refuses it (it's an
              embedded system). I end up with "bad sequence of commands", which is bit
              different than what original poster gets.
              Hi Goran,
              according to the trace, the response is returning 500
              Unknown Command from a User request. So it appears to be the problem that
              you talked about. How did you get round it.


              Comment

              • Goran Sliskovic

                #8
                Re: FtpWebRequest DeleteFile Problem


                "Waldy" <someone@micros oft.comwrote in message
                news:u6N3PZdDJH A.4824@TK2MSFTN GP03.phx.gbl...
                "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
                news:O3iKGOPDJH A.484@TK2MSFTNG P05.phx.gbl...
                >
                >Yes, sniffer should reveal the problem. I had similar problem with UNIX
                >based system and FTPWebRequest. FTPWebRequest is cacheing connections to
                >FTP
                >server and reuses the connection between commands. However, it resend
                >USER/PASS commands even on already connected and authorized connection
                >(and
                >that is allowed according to standard) and UNIX server refuses it (it's
                >an
                >embedded system). I end up with "bad sequence of commands", which is bit
                >different than what original poster gets.
                >
                Hi Goran,
                according to the trace, the response is returning 500
                Unknown Command from a User request. So it appears to be the problem that
                you talked about. How did you get round it.
                >
                Hi,
                I gave up FTPWebRequest.. . Found some ugly FTP client code on the internet,
                fixed few bugs and it's working now. You may try to set keepalive to false,
                however that has some side effects (reconnect on every command).

                Regards,
                Goran

                Comment

                • Waldy

                  #9
                  Re: FtpWebRequest DeleteFile Problem


                  "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
                  news:Orer3jgDJH A.4428@TK2MSFTN GP06.phx.gbl...
                  >
                  >You may try to set keepalive to false, however that has some side effects
                  >(reconnect on every command).
                  >
                  Regards,
                  Goran
                  Good man! That's fixed it for me.


                  Comment

                  • Goran Sliskovic

                    #10
                    Re: FtpWebRequest DeleteFile Problem


                    "Waldy" <someone@micros oft.comwrote in message
                    news:uYlp6gpDJH A.2612@TK2MSFTN GP06.phx.gbl...
                    >
                    "Goran Sliskovic" <gsliskov@yahoo .comwrote in message
                    news:Orer3jgDJH A.4428@TK2MSFTN GP06.phx.gbl...

                    You may try to set keepalive to false, however that has some side effects
                    (reconnect on every command).

                    Regards,
                    Goran
                    >
                    Good man! That's fixed it for me.
                    >
                    >
                    Keep in mind that this will (probably) open/close TCP connection for every
                    command. If you have lot of commands (eg. files to delete) this is not free.
                    It will depend on the network infrastructure/project you are working on
                    whether this turns to real problem. You could possibly be cut by routers in
                    between as a result of false attack detection in some cases. It sucked for
                    me (connecting to embedded system over slow/high latency links). It is
                    relativly cheap to create interface and allow implementation to change. But
                    that depends on your project requirements.

                    Regards,
                    Goran


                    Comment

                    Working...