从服务器下载FTP文件出现问题
问题如下:
System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FtpDataStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadLine()
各位大虾,这会不会是服务器内存不足导致呢?代码如下
public void FTPFile()
{
int i = 0;
int k = 0;
string temp_strServer = "ftp://××××";
string temp_remoteFile = "XXX.tab";
string temp_userID = "×××";
string temp_passWord = "×××";
Uri temp_URI = new Uri(temp_strServer + temp_remoteFile);
string temp_localFilePath = Application.StartupPath + "/temp/";
try
{
currentTime = DateTime.Now;
WriteLog("---begin FTP---" + currentTime);
FtpWebRequest ftpReq = (FtpWebRequest)WebRequest.Create(temp_URI);
ftpReq.Method = WebRequestMethods.Ftp.DownloadFile;
ftpReq.UseBinary = true;
ftpReq.Credentials = new NetworkCredential(temp_userID, temp_passWord);
FtpWebResponse ftpResp = (FtpWebResponse)ftpReq.GetResponse();
StreamReader ftpRespStream = new StreamReader(ftpResp.GetResponseStream());
// Stream ftpRespStream = ftpResp.GetResponseStream();