FTP problems

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

    FTP problems

    (Multi-post from microsoft.publi c.dotnet.framew ork.aspnet.webs ervices,
    Please apply all applicable pardons.)

    Hi all,

    I have a web service that FTPs data it receives to a third party
    FTP site.

    The web service will upload to the FTP site 12 times. The 13th
    time it will timeout. Once the web service is reset - that is
    modified in some way that IIS is forced to unload and JIT, then
    it will upload an additional 12 times. This behavior is
    remarkably consistent.

    Note it does not matter what FTP site I upload to. I tested
    against a server on my local LAN and it fails the same way.

    This behavior leads me to believe that some session limit is being
    reached, however the FTP site will allow 100,000 connections, and
    in the test I uploaded once each second, but in production the files
    come in hours apart. Plenty of time for the FTP server to dump any
    possible open sessions.

    The Web service will function normally for many hours until 12
    upload are done, then I get FTP server timeouts.

    Just as remarkable however, after about 6 hours, the FTP site will
    again be accessible and an additional 12 uploads can be processed.

    Actually the number of uploads is 24, since each post to the web
    service results in 2 uploads to the FTP site.

    Note that the FTP server is up and running with no problems while
    the web service is failing and reporting a timeout, and the FTP
    logs show no activity at all.

    All this on a server that has many other functioning web services,
    although none dealing with FTP transfers.

    Any ideas? This is driving me nuts.

    Thanks,
    kpg


    Here is the FTP upload code:

    Private Function Upload(ByVal FTPPath As String, ByVal Data As
    String, Optional ByVal UserName As String = "", Optional ByVal Password
    As String = "") As Boolean

    Try

    Dim buffer As Byte() = Encoding.UTF8.G etBytes(Data)

    Dim ftp As FtpWebRequest = CType(FtpWebReq uest.Create
    (FTPPath), FtpWebRequest)
    If UserName.Length <0 Then
    ftp.Credentials = New NetworkCredenti al(UserName,
    Password)
    End If

    ftp.KeepAlive = False
    ftp.UseBinary = True
    ftp.Method = WebRequestMetho ds.Ftp.UploadFi le
    ftp.GetRequestS tream().Write(b uffer, 0, buffer.Length)

    Upload = True

    Catch ex As Exception

    WriteToLog("Upl oad Error: " & ex.Message)

    End Try

    End Function
  • =?Utf-8?B?Sm95?=

    #2
    RE: FTP problems

    Hi,
    While going thru your code it appears to me that once you are done with
    writing the file you dont close the stream.

    can you do a ".close()" on your stream and then try the code?

    Let me know if the problem still persists.

    regards,
    Joy

    "kpg" wrote:
    (Multi-post from microsoft.publi c.dotnet.framew ork.aspnet.webs ervices,
    Please apply all applicable pardons.)
    >
    Hi all,
    >
    I have a web service that FTPs data it receives to a third party
    FTP site.
    >
    The web service will upload to the FTP site 12 times. The 13th
    time it will timeout. Once the web service is reset - that is
    modified in some way that IIS is forced to unload and JIT, then
    it will upload an additional 12 times. This behavior is
    remarkably consistent.
    >
    Note it does not matter what FTP site I upload to. I tested
    against a server on my local LAN and it fails the same way.
    >
    This behavior leads me to believe that some session limit is being
    reached, however the FTP site will allow 100,000 connections, and
    in the test I uploaded once each second, but in production the files
    come in hours apart. Plenty of time for the FTP server to dump any
    possible open sessions.
    >
    The Web service will function normally for many hours until 12
    upload are done, then I get FTP server timeouts.
    >
    Just as remarkable however, after about 6 hours, the FTP site will
    again be accessible and an additional 12 uploads can be processed.
    >
    Actually the number of uploads is 24, since each post to the web
    service results in 2 uploads to the FTP site.
    >
    Note that the FTP server is up and running with no problems while
    the web service is failing and reporting a timeout, and the FTP
    logs show no activity at all.
    >
    All this on a server that has many other functioning web services,
    although none dealing with FTP transfers.
    >
    Any ideas? This is driving me nuts.
    >
    Thanks,
    kpg
    >
    >
    Here is the FTP upload code:
    >
    Private Function Upload(ByVal FTPPath As String, ByVal Data As
    String, Optional ByVal UserName As String = "", Optional ByVal Password
    As String = "") As Boolean
    >
    Try
    >
    Dim buffer As Byte() = Encoding.UTF8.G etBytes(Data)
    >
    Dim ftp As FtpWebRequest = CType(FtpWebReq uest.Create
    (FTPPath), FtpWebRequest)
    If UserName.Length <0 Then
    ftp.Credentials = New NetworkCredenti al(UserName,
    Password)
    End If
    >
    ftp.KeepAlive = False
    ftp.UseBinary = True
    ftp.Method = WebRequestMetho ds.Ftp.UploadFi le
    ftp.GetRequestS tream().Write(b uffer, 0, buffer.Length)
    >
    Upload = True
    >
    Catch ex As Exception
    >
    WriteToLog("Upl oad Error: " & ex.Message)
    >
    End Try
    >
    End Function
    >

    Comment

    • kpg

      #3
      RE: FTP problems

      Hi,
      While going thru your code it appears to me that once you are done
      with
      writing the file you dont close the stream.
      >
      can you do a ".close()" on your stream and then try the code?
      >
      Let me know if the problem still persists.
      >
      regards,
      Joy
      I see your point. There are code examples out there
      that create a stream variable and assign it the value
      of ftp.GetRequestS tream, then when complete they
      close the stream. I perhaps incorrectly assumed that
      the inplace GetRequestStrea m used below closed the stream
      itself once completed.

      Incidentally, as the code below does not use an explicit
      stream object, how would it be closed in this case?

      ftp.GetRequestS tream().close ?

      I would try it but I found a different solution that
      works.

      I replaced this:

      Dim ftp As FtpWebRequest = _
      CType(FtpWebReq uest.Create(FTP Path),FtpWebReq uest)
      ftp.Credentials = New NetworkCredenti al(UserName,
      ftp.KeepAlive = False
      ftp.UseBinary = True
      ftp.Method = WebRequestMetho ds.Ftp.UploadFi le
      ftp.GetRequestS tream().Write(b uffer, 0, buffer.Length)

      with this:

      Dim ftp As New WebClient
      ftp.Credentials = New NetworkCredenti al(UserName, Password)
      ftp.UploadData( FTPPath, buffer)

      and that corrected the problem.

      I have little doubt that either the stream (seems likely)
      or something else was not being cleaned up properly, but
      calling the higher level WebClient object's UploadData
      method does any needed closing and cleanup for me.

      When I searched for an ASP.NET 2.0 FTP examples I found
      many using the ftpWebRequest object, but it took some
      looking to discover the WebClient technique, which in
      my mind is better because it works (!) and does so in
      fewer lines of code.

      I'm sure it uses the ftpWebRequest underneath, however.

      Also in defense of the ftpWebRequest technique, most
      examples used an explicit stream object that was then
      closed in code, so that may well be the problem. I don't
      noramlly like condensing the code down to one-liners
      but in this case I did use that particular example.

      Go Figure.

      Thanks,
      kpg


      Comment

      • =?Utf-8?B?Sm95?=

        #4
        RE: FTP problems

        Hi,
        I am glad to know that finally you could get it working.

        As far as calling the ".close()" function goes, for that you would need to
        first make a stream object and close it as is given below

        Using requestStream As System.IO.Strea m = ftp.GetRequestS tream()
        'The rest of the code goes here
        requestStream.C lose()
        End Using

        And you got it right, the most of the problem was attributed to the fact
        that the clean up was not being done properly.

        regards,
        Joy

        "kpg" wrote:
        Hi,
        While going thru your code it appears to me that once you are done
        with
        writing the file you dont close the stream.

        can you do a ".close()" on your stream and then try the code?

        Let me know if the problem still persists.

        regards,
        Joy
        >
        I see your point. There are code examples out there
        that create a stream variable and assign it the value
        of ftp.GetRequestS tream, then when complete they
        close the stream. I perhaps incorrectly assumed that
        the inplace GetRequestStrea m used below closed the stream
        itself once completed.
        >
        Incidentally, as the code below does not use an explicit
        stream object, how would it be closed in this case?
        >
        ftp.GetRequestS tream().close ?
        >
        I would try it but I found a different solution that
        works.
        >
        I replaced this:
        >
        Dim ftp As FtpWebRequest = _
        CType(FtpWebReq uest.Create(FTP Path),FtpWebReq uest)
        ftp.Credentials = New NetworkCredenti al(UserName,
        ftp.KeepAlive = False
        ftp.UseBinary = True
        ftp.Method = WebRequestMetho ds.Ftp.UploadFi le
        ftp.GetRequestS tream().Write(b uffer, 0, buffer.Length)
        >
        with this:
        >
        Dim ftp As New WebClient
        ftp.Credentials = New NetworkCredenti al(UserName, Password)
        ftp.UploadData( FTPPath, buffer)
        >
        and that corrected the problem.
        >
        I have little doubt that either the stream (seems likely)
        or something else was not being cleaned up properly, but
        calling the higher level WebClient object's UploadData
        method does any needed closing and cleanup for me.
        >
        When I searched for an ASP.NET 2.0 FTP examples I found
        many using the ftpWebRequest object, but it took some
        looking to discover the WebClient technique, which in
        my mind is better because it works (!) and does so in
        fewer lines of code.
        >
        I'm sure it uses the ftpWebRequest underneath, however.
        >
        Also in defense of the ftpWebRequest technique, most
        examples used an explicit stream object that was then
        closed in code, so that may well be the problem. I don't
        noramlly like condensing the code down to one-liners
        but in this case I did use that particular example.
        >
        Go Figure.
        >
        Thanks,
        kpg
        >
        >
        >

        Comment

        Working...