473,513 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FTP problems

kpg
(Multi-post from microsoft.public.dotnet.framework.aspnet.webservic es,
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.GetBytes(Data)

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

ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = WebRequestMethods.Ftp.UploadFile
ftp.GetRequestStream().Write(buffer, 0, buffer.Length)

Upload = True

Catch ex As Exception

WriteToLog("Upload Error: " & ex.Message)

End Try

End Function
Jun 27 '08 #1
3 1548
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.public.dotnet.framework.aspnet.webservic es,
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.GetBytes(Data)

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

ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = WebRequestMethods.Ftp.UploadFile
ftp.GetRequestStream().Write(buffer, 0, buffer.Length)

Upload = True

Catch ex As Exception

WriteToLog("Upload Error: " & ex.Message)

End Try

End Function
Jun 27 '08 #2
kpg
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.GetRequestStream, then when complete they
close the stream. I perhaps incorrectly assumed that
the inplace GetRequestStream 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.GetRequestStream().close ?

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

I replaced this:

Dim ftp As FtpWebRequest = _
CType(FtpWebRequest.Create(FTPPath),FtpWebRequest)
ftp.Credentials = New NetworkCredential(UserName,
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = WebRequestMethods.Ftp.UploadFile
ftp.GetRequestStream().Write(buffer, 0, buffer.Length)

with this:

Dim ftp As New WebClient
ftp.Credentials = New NetworkCredential(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
Jun 27 '08 #3
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.Stream = ftp.GetRequestStream()
'The rest of the code goes here
requestStream.Close()
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.GetRequestStream, then when complete they
close the stream. I perhaps incorrectly assumed that
the inplace GetRequestStream 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.GetRequestStream().close ?

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

I replaced this:

Dim ftp As FtpWebRequest = _
CType(FtpWebRequest.Create(FTPPath),FtpWebRequest)
ftp.Credentials = New NetworkCredential(UserName,
ftp.KeepAlive = False
ftp.UseBinary = True
ftp.Method = WebRequestMethods.Ftp.UploadFile
ftp.GetRequestStream().Write(buffer, 0, buffer.Length)

with this:

Dim ftp As New WebClient
ftp.Credentials = New NetworkCredential(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
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2069
by: Jerome Lefebvre | last post by:
Hello, Hope this will interest a few. I been working with a friend on the problems given out during the "International Collegiate Programming Contest" (ICPC) http://icpc.baylor.edu/icpc/ ....
14
2290
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
3026
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
8780
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
2
2310
by: Ellen Graves | last post by:
I am having a lot of problems with DB2 8.3.1 on RH Linux AS2.1. Installing and running stored procedures is problematic. Stored procedures I have used for years on V7 on WinNT are now failing...
19
3112
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
10
2382
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
19
2952
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
2
3157
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
2222
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.