KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an API that takes in XML and ultimately uploads files based on information in the XML. The uploads are on a schedule (also from XML), and I have tested everything surrounding it and know it works. I am getting an error about 40% of the time on the first file that I attempt to upload in each time cycle (time cycle = 45 minutes for some files, 30 minutes for others). Here is my code for the upload: try { LoggerFTP.Log("Uploading file: " + filename, false); // Create the request. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(appSettingsFTP.ftpUrl + @"/" + filename); request.Method = WebRequestMethods.Ftp.UploadFile; request.Timeout = 6000000; //set to 100 minutes //request.Timeout = -1; //set to infinite // Add the login credentials. request.Credentials = new NetworkCredential(appSettingsFTP.ftpLogin, appSettingsFTP.ftpPassword); // Grab the file contents. StreamReader sourceStream = new StreamReader(appSettingsFTP.uploadFileDirectory + filename); byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; // Copy the file contents to the outgoing stream. Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); //Logger.Log(filename.ToString() + " " + "Upload Complete, Status: " + response.StatusCode + " " + response.StatusDescription, false); //Took response.StatusDescription out because it appears to be creating extra line feeds. LoggerFTP.Log(filename.ToString() + " " + "Upload Complete, Status: " + response.StatusCode, false); } catch (Exception ex) { LoggerFTP.Log(ex.ToString(), false); } I have researched the issue and saw something online about it potentially being a speed thing. Lik
Tags (comma-separated)
Save Edits
Cancel