I've created a simple windows service that checks a FTP folder every 20 seconds and copies any files to the computer locally.
In debug mode it works perfectly, however when I install the release using installutil I catch the following error when calling
using (response = reqFTP.GetResponse())
FTP error...System.Net.WebException: The operation has timed out at System.Net.FtpWebRequest.SyncRequestCallback(Object obj) at System.Net.FtpWebRequest.RequestCallback(Object obj) at System.Net.CommandStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Stream.Dispose() at System.Net.ConnectionPool.Destroy(PooledStream pooledStream) at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse) at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) at System.Net.FtpWebRequest.GetResponse() at FileMan.Service1.GetFileList() in....
The full request is as follows;
string[] downloadFiles;
StringBuilder result = new StringBuilder();
WebResponse response = null;
StreamReader reader = null;
textWrite.WriteLine("attempting to get file list" + DateTime.Now + Environment.NewLine, true);
try
{
FtpWebRequest reqFTP;
ServicePointManager.DefaultConnectionLimit = 100;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(downloadSrc));
reqFTP.UseBinary = true;
textWrite.WriteLine("requestFTP...Passed..." + DateTime.Now + Environment.NewLine, true);
//reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.Proxy = null;
reqFTP.KeepAlive = true;
reqFTP.UsePassive = false;
reqFTP.Timeout = 8000;
//////////STOPS HERE
//response = reqFTP.GetResponse();
using (response = reqFTP.GetResponse())
{
// Do stuff
//...
reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
return result.ToString().Split('\n');
}
}
catch (Exception ex)
{
textWrite.WriteLine("FTP error..." + ex + "..." + DateTime.Now + Environment.NewLine, true);
textWrite.Close();
if (reader != null)
{
reader.Close();
}
if (response != null)
{
response.Close();
}
downloadFiles = null;
return downloadFiles;
}
Are there any permissions i need to add? As this works in debug mode, the code itself is fine. I just needed to figure out what was blocking it
P.S. I'm using LocalSystem as the Account and im copying the release build directly to the c drive before installing it using installutil.