.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

FtpWebRequest and timeouts

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :.NET Framework
i'm using the FtpWebRequest class as used in the SDK examples.  i find that when an upload takes a few minutes, the call to GetResponse() fails with "Underlying connection closed", even though the upload was successful.  i'm not changing the Timeout value, but i do have KeepAlive set to true, in an effort to keep the connection active. 

i guess it's a timeout after such a long upload, but i'm wondering if i need to bother calling GetResponse at all?  if there was an error streaming the file, surely it would raise it's own exception and not wait for me to call GetResponse?


View Complete Post

More Related Resource Links

Session Timeouts


What are the issues (if any) of setting sessions to expire after an extended period of time as in 4-8 hours? I'm building an intranet app which is designed so that users will access it once in the morning and then leave it used, possibly, for hours at a time. I'm assuming that there aren't too many since

1) we're running it on a intranet
2) sessions are soley to retain state between requests
3) its not like a connection to the DB where you can conceivable run out

page load timeouts and http 500 on MOSS2007


Hi All

I'm hoping someone can point me in the right direction re troubleshooting. We have a MOSS server farm - 3 WFE 1 APP 1 SQL cluster. All Server 2008 sp1 x64. We see occasional http timeouts (HttpException (0x80004005): Request timed out) with associated http 500 error. I have enabled failed request tracing and can see the following:

SiteId 754431215
AppPoolId SharePoint - intranet.*********.com80
ConnId 1610966466
RawConnId 0
RequestURL http://intranet.*********.com:80/Pages/default.aspx
RequestVerb GET

and then later in the trace:

ModuleName IsapiModule
Notification 128
HttpStatus 500
HttpReason Internal Server Error
HttpSubStatus 0
ErrorCode 0
ErrorCode The operation completed successfully. (0x0)

The problem happens on other pages too but the rest of the time the page is returned in less than 5 seconds. The server app logs and sharepoint ULS logs do not give any more detailed info. What I want to know is what other troubleshooting step can I take for http500 errors.

In the past on 32bit environments I have used de

FtpWebRequest - how to upload two files on FTP server using only one connection?

Hi I am using FtpWebRequest with option KeepAlive = true. When I upload first file I create ftp request object: FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create(""); I set KeepAlive = true and I do upload file. When I want upload second file I have to create new FtpWebRequest object using new URI FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create("");   I set KeepAlive = true and I do upload file. The problem is that I have to create new FtpWebRequest so I create new connection to FTP server (I have checked using netstat -b command that my application uses another port number for second file). How can I upload two files (or more) using only on FTP connection/session? Regards  

Unable to use FTPWebRequest over SSL

Hi   I have been trying to connect to a FTP server using SSL. I have followed the example on MSDN - ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref10/html/P_System_Net_FtpWebRequest_EnableSsl.htm However I keep getting an exceptions when then "request.GetResponse" method is called. The exceptions is "WebException" and message is "The underlying connection was closed: The server committed a protocol violation"   Does anybody have any working example to connect to a FTP server over SSL? Thanks for your help.

FtpWebRequest.EnableSSL error

I'm getting a "The remote certificate is invalid according to the validation procedure" Authentication Exception message with the following code:   ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(MyCertValidationCb); var request = (FtpWebRequest)WebRequest.Create(new Uri(myUri)); request.EnableSsl = true; request.Method = WebRequestMethods.Ftp.UploadFile; request.BeginGetRequestStream(EndGetStreamCallback, _state); public static bool MyCertValidationCb(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) == SslPolicyErrors.RemoteCertificateChainErrors) { return false; } if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateNameMismatch) == SslPolicyErrors.RemoteCertificateNameMismatch) { Zone z; z = Zone.CreateFromUrl(((FtpWebRequest)sender).RequestUri.ToString()); if (z.SecurityZone == SecurityZone.Intranet || z.SecurityZone == SecurityZone.MyComputer) { return true; } return false; } return false; } The ftp server is filezilla. FTP over SSL is enabled, and Allow explicit FTP over TLS is also enabled. I've generated a certificate.crt file. Connected to the ftp location using filezilla client, and checked "Always trust

Session Variables and Session Timeouts

I added the following code to global.asax to load up several session variable when a session starts. I'm assuming that when a page goes to use the variable that I should be 1) checking at the page level that the value is valid not 0 when its not expected to be 0, not a zero-length string when its expected to have a length 2) have code at the page level that sets the values if the values have not been set as when the Session timeout, ideally putting the code in a class derived from Page and then deriving all of my pages from the new class so that the code does not have to be repeated in every page Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started 'Move code here that sets the User Session Variables, currently done in the code behind of DefaultDirectory and the Dashboard Masters Dim ExceptionMessage As New StringBuilder ExceptionMessage.Append("Site accessed using " + Request.Browser.Browser + " " + Request.Browser.MajorVersion.toString + "." + Request.Browser.MinorVersion.tostring) Dim NewException As New NotSupportedException(ExceptionMessage.ToString) Elmah.ErrorSignal.FromCurrentContext().Raise(NewException) Dim CurrentUser As New MercurySiteUser.SiteUser() Session("UserE

Azure ASP.Net VS2010 Timeouts during debug

Hi All,I've converted an ASP.Net website over to an Azure version and I've got it up and running. However the vast majority of the time I experience timeouts when I'm trying to debug the application.This seems to happen on any page at any time. I start debugging from VS2010 and sometimes the home page will come up sometimes it hangs. When it does come up if I select an item from a drop down list sometimes it works somtimes it times out. I have breakpoints set and they don't even fire I just eventually get the time out. If I hit refresh that sometimes seems to fix it but it eventually starts happening again. This is making the completion of the conversion VERY difficult and I'm starting to creep up to a deadline.Does anyone have any idea what might be happening? If there is a better location I can post this question to would someone be kind enough to point me in the right direction?Thanks in advance for any help and in addition my email is mgorgone@pictureu.com as our Windows Live account email is diff. Cheers,Mike 

Timeouts specified in web.config seem to be ignored

Here’s the situation…   1)      This is related to timeouts on calls to stored procedures in the database. 2)      The timeout value set in the web.config file was 300 seconds as follows: <add name="XXX" connectionString="Server=eve.wctnet.org;Database=XXXP_Prog;Uid=xxx_user;Pwd=xxxxxxConnect Timeout=300" providerName="System.Data.SqlClient" /> 3)      When executing a form/page with a call to GetIntPerAndSpouse, the page/form would timeout after about 20 seconds. 4)      So, we added code to the code-behind for one InfoPath form as follows: Cmd.CommandTimeout = 300; 5)      And, then the procedure completed normally – in about 40 seconds.   So, obviously, the timeout set in the web.config file was not having any effect.   So the question we have is What could be causing the web.config file setting to be ignored Is there a setting the we may not have set?  Since this application has a considerable number of form, using the CMD.COMMANDTIMEOUT in all of them seem like a lot of work if we could get the web.config file to do it for us.   thanks greg

Send/open timeouts on WAS-hosted WCF service with named pipe orTCP binding, per-call instancing

We have a client that sends requests to a per-call WCF service (WAS hosted, NP binding, same machine) in a loop. The WCF service calls an external EXE to process requests. The operations on the service can take a few seconds, or a few hours. To combat this, we have sendTimeout=00:05:00, receiveTimeout=00:05:00 and a built-in circuit-breaker on the service that kills the external process after 00:05:00. Any service-side errors are returned to the client as FaultExceptions.  On the client, FaultExceptions are logged and the client proxy is aborted (proxy.Abort()). The client has configurable multithreading. In this example, it is running 3 threads, each of which creates a proxy, makes a call, and closes the proxy (or aborts it if an exception was received). Since the service is instanced as per-call, and it never receives more than 3 simultaneous calls (each of which being followed by a .Close() or .Abort() on the proxy), I would not expect the client to be getting timeouts during the send, but I am. In fact, the send timeouts I am receiving would seem to imply that the WCF service is hitting the default session limit, even though the class is explicitly marked with [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]. I put some trace logging on the client and I can see that the timeout is occurring when the proxy is being created. sendTimeout seems to

FTPWebRequest to VMS system


Hello and how is it? I believe this error is due to the directory listing set to MS-DOS, but I want to validate this first. when I call the getRequestStream() I recieve this WebException error: 550-Failed to set default directory to DISK$SMSUSER1^:^[MyUser^]. 550 invalid directory.


If this is due to the directory listing style not set to VMS can I change this with in the FTPWebRequest class? Thanks Smile




FTPWebRequest Issue


I have written the following code that successful ftps a file to the proper location as long as the file exists on the server itself....

However, I need the code to pull the file contents from the client computer, not the server. 

Here is the code:

        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
            if (Page.IsValid)
                    FtpWebRequest ftpr = 
                        (FtpWebRequest)FtpWebRequest.Create(@"ftp://" + ConfigurationManager.AppSettings["remoteHost"] + "/" + 
                                                                        ConfigurationManager.AppSettings["remotePath"] + "/" + 

                    ftpr.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["remoteUser"].ToString(), 

FtpWebRequest GetResponse Error on Linux Server but work on Windows Server



I have a big problem when I tried to list directory from FTP Server on linux but using the FtpWebRequest.

An error occurs at the GetResponse() method but the same code work fine on Windows Server (IIS).

The error is :

The remote server returned an error: (550) File unavailable (e.g., file not found, no access).
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.InvokeRequestCallback(Object obj)
   at System.Net.CommandStream.Abort(Exception e)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.GetResponse()
   at FilePostman.Program.GetListFtp(NodeItem item)
   at FilePostman.Program.ReceiveFtp(NodeItem item)
   at FilePostman.Program.Main(String[] args)

The information that I use when run time like this:

Windows 2003

  Host :

  path : fmd/inbox

  uri :

  User : administrator

  Password : *******


FtpWebRequest - Access to IBM AS/400 FTP Server - 501 Character (/) not allowed in object name.

Hello everybody

I'm trying to communicate with an AS/400 FTP Server. As a first try I just execute the WebRequestMethods.Ftp.ListDirectory method, which translates to the NLST FTP command. Doing the same accessing a Microsoft FTP Server or a UNIX FTP Server works fin.

This is the code to get the listing:

Dim Uri As System.Uri = New System.Uri(listUrl)
Dim listRequest As FtpWebRequest = CType(WebRequest.Create(Uri), FtpWebRequest)
listRequest.Credentials = New System.Net.NetworkCredential(User, Password)listRequest.Method = WebRequestMethods.Ftp.ListDirectory
listRequest.KeepAlive =
listRequest.UseBinary =

FtpWebRequest + sftp


Hi All,

I need a program that would download all csv files from an sftp location. I've the sftp host IP, user name, password and port details of the sftp location. I am able to login through Filezilla. But as I need to login programmatically, so that I can get a list of all files in the folder.

When the code works fine for a ftp request, it doesn't for an sftp request. Given below is my code to connect to the ftp uri.

FtpWebRequest FtpRequest = (FtpWebRequest)WebRequest.Create("ftp://myuri");
FtpRequest.Credentials = new NetworkCredential("username", "password");
FtpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;

My system admin says that there is no uri that could be given for sftp sites at all. Now, how can I go about this? Is there any third party tool available for this? If yes, suggest me some good ones.

Thanks in advance.





How do I gracefully handle Session Timeouts?


Can I still use Session_OnEnd to trap a session timeout?  Is there a better way to trap a session timeout?  I want to take the user to a page that tells them the session timed out, and give them an opportunity to re-enter the application in a new session if they wish. 

How can I accomplish this?  Is there still a global.asax file in the .NET 4.0 world? 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend