views:

50

answers:

0

I have a basic asp.net file upload page. When I test file uploads from my local machine, it works fine. When I test file uploads from our dev machine, it works fine. When I deploy the site to our production webfarm, it behaves strangely.

If I access the site from off the network, I can load file-after-file without issue. If I access the site from within our network, I can load the first file just fine but any subsequent files result it a bad sequence of commands error.

I'm not sure if this is web farm issue, a network issue, or something else. It feels like a connection is not being disposed of properly but it doesn't make sense why everything works fine remotely.

Markup:

<asp:FileUpload ID="FileUpload1" runat="server" Width="350px" />
<asp:Button ID="btnSubmit" runat="server" Text="Upload" onclick="btnSubmit_Click" />

Code:

if (FileUpload1.HasFile)
{
    FtpWebRequest ftpRequest;
    FtpWebResponse ftpResponse;
    ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://ftp.myftpsite.com/" + FileUpload1.FileName));
    ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
    ftpRequest.Proxy = null;
    ftpRequest.UseBinary = true;
    ftpRequest.Credentials = new NetworkCredential("username", "password");
    ftpRequest.KeepAlive = false;
    byte[] fileContents = new byte[FileUpload1.PostedFile.ContentLength];
    using (Stream fr = FileUpload1.PostedFile.InputStream)
    {
        fr.Read(fileContents, 0, FileUpload1.PostedFile.ContentLength);
    }
    using (Stream writer = ftpRequest.GetRequestStream())
    {
        writer.Write(fileContents, 0, fileContents.Length);
    }
    ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
    Response.Write(ftpResponse.StatusDescription);
}