1
FTP에 초보자입니다. StreamWriter를 사용하여 FTP로 파일에 쓰려고합니다. 파일에 기록한 후 한 번 , 나는 스트림을 닫고 싶지 않다. 내가 done.Later 몇 시간 후에, 내가 같은 streamWriter를 사용하여 쓰려고하면 위의 오류가 발생합니다. 다음은FTP : 전송 연결에 데이터를 쓸 수 없습니다. 기존 연결이 원격 호스트에 의해 강제로 닫혔습니다.
당신이 무한대로 timout 설정해야합니다public void WriteToFTP()
{
bool isConnectionEstablished = false;
StreamWriter stream = null;
try
{
for (int i = 1; i < 5; i++)
{
string message = string.Format("File - {0}.", i.ToString());
if (!isConnectionEstablished)
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("My FTP path"));
request.Credentials = new NetworkCredential("asdf", "[email protected]");
request.Proxy = null;
request.UseBinary = true;
request.ConnectionGroupName = string.Empty;
request.UsePassive = true;
request.EnableSsl = false;
isConnectionEstablished = true;
stream = new StreamWriter(request.GetRequestStream()) { AutoFlush = true };
}
stream.WriteLine(message);//Here i am getting the error for the i = 2(after doing my work)
//Doing work which may take more than 1 hour.
}
}
catch (Exception exe)
{
//The Error "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host" is being caught here.
}
finally
{
if (stream != null)
stream.Close();
}
}
그것의 기본 값은 infinate 것 같다을! – Venkatesh