我得到了很多不同的问题,在这个函数:错误到来,同时将图像上传到FTP
public static bool UploadToFTP(string strFileName, string strFolderName)
{
bool isUploaded = false;
string strFilename = string.Empty;
string strFtpURI = string.Empty;
string strFtpUserId = string.Empty;
string strFtpPassword = string.Empty;
byte[] buffer = null;
FileInfo oFileInfo = null;
FileStream oFileStream = null;
FtpWebRequest oFtpWebRequest = null;
try
{
strFilename = strFileName;
oFileInfo = new FileInfo(strFilename);
strFtpURI = Constants.FtpUri;
strFtpUserId = Constants.FtpUserID;
strFtpPassword = Constants.FtpPassword;
oFtpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpURI + "/" + strFolderName + "/" + oFileInfo.Name));
oFtpWebRequest.Credentials = new NetworkCredential(strFtpUserId, strFtpPassword);
oFtpWebRequest.Proxy = null;
oFtpWebRequest.KeepAlive = false;
oFtpWebRequest.Method = WebRequestMethods.Ftp.UploadFile;
oFtpWebRequest.UseBinary = true;
oFtpWebRequest.ContentLength = oFileInfo.Length;
int iBufferLength = 2084;
buffer = new byte[iBufferLength];
int iContentLength = 0;
oFileStream = oFileInfo.OpenRead();
try
{
iContentLength = oFileStream.Read(buffer, 0, iBufferLength);
using (Stream oStream = oFtpWebRequest.GetRequestStream())
{
while (iContentLength != 0)
{
oStream.Write(buffer, 0, iContentLength);
iContentLength = oFileStream.Read(buffer, 0, iBufferLength);
}
isUploaded = true;
FtpUpload.TotalKBFilesUploaded = FtpUpload.TotalKBFilesUploaded + (int)(oFileInfo.Length/1000);
}
}
catch (Exception ex)
{
}
finally
{
if (oFtpWebRequest != null)
{
oFtpWebRequest.Abort();
oFtpWebRequest = null;
}
if (buffer != null)
{
buffer = null;
}
if (oFileStream != null)
{
oFileStream.Close();
oFileStream.Dispose();
}
}
}
catch (Exception ex)
{
}
finally
{
oFileInfo = null;
}
return isUploaded;
}
这是上传图片的1000至FTP,这methos就是所谓的多线程方式。
不同的错误是:
===================================== ==================
信息:操作已超时
错误跟踪:在System.Net.FtpWebRequest.CheckError()在系统。 Net.FtpWebRequest.GetRequestStream()
====================================== =================
错误消息:无法
错误跟踪连接到远程服务器:在System.Net.FtpWebRequest.GetRequestStream()在System.Net.FtpWebRequest.CheckError()
=== ================================================== ==
错误消息:底层连接已关闭:接收方发生意外错误。
错误跟踪:System.Net.FtpWebRequest.FinishRequestStage上的System.Net.FtpWebRequest.CheckError()在System.Net.FtpWebRequest.SyncRequestCallback(Object obj)System.Net.CommandStream.Abort(Exception e) RequestStage阶段)在System.Net.FtpWebRequest.GetRequestStream()
================================ =======================
错误消息:无法将数据写入传输连接:连接尝试失败,因为关联方没有在一段时间后正确响应,或建立的连接失败,因为连接的主机无法响应OND。
错误跟踪:在System.Net.Sockets.NetworkStream.Write(字节[]缓冲液,的Int32偏移的Int32大小)在System.Net.FtpDataStream.Write(字节[]缓冲液,的Int32偏移的Int32大小) ================================================= ======
这些都是从我从LOG文件检索相同的方法来的几个错误。
任何想法可能会造成这种情况?或者我需要提供更多的细节?
看起来你需要**在你的组织**中对你的n/w家伙说话。我看到所有错误都是“无连接问题”或“服务器没有响应”! – SridharVenkat