我必须在服务器上一次上传 1000 到 1500 张图片。代码如下。
public void add_data()
{
DataSet ds = new DataSet();
ds = get_Data();
int p = 0;
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
int cnt = ds.Tables[0].Rows.Count;
while (cnt > 0)
{
string url = Convert.ToString(ds.Tables[0].Rows[p]["image_name"]);
string imagename = url.Substring(url.LastIndexOf('/') + 1);
string file_name = imagename;
save_file_from_url(file_name, url);
p++;
cnt = cnt - 1;
}
}
}
}
public void save_file_from_url(string file_name, string url)
{
if (!File.Exists(file_name))
{
try
{
byte[] imgcontent;
//Convert live images into byte array to pass it for ftp server
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
using (BinaryReader br = new BinaryReader(stream))
{
imgcontent = br.ReadBytes(500000);
br.Close();
}
response.Close();
string CompleteDPath = "www.xyz.com";
string UName = "abc";
string PWD = "pwd";
WebRequest reqObj = WebRequest.Create(CompleteDPath + file_name);
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
reqObj.Credentials = new NetworkCredential(UName, PWD);
reqObj.GetRequestStream().Write(imgcontent, 0, imgcontent.Length);
reqObj = null;
}
catch (Exception ex)
{
lblmessage.ForeColor = System.Drawing.Color.Red;
lblmessage.Text = ex.Message;
}
}
}
但它给出了以下错误
遇到以下错误:
Read Timeout
系统返回:
[No Error]
等待从网络读取数据时发生超时。网络或服务器可能已关闭或拥塞。请重试您的请求。
您的缓存管理员是网站管理员。
我应该用什么?请帮忙!