解决方案 »
- ★关于防火墙穿透的问题,知道的进来下!~~
- WCF客户端和服务器之间的连接问题。。
- [求助]如何已有DataTable中数据的多列聚合
- Datetime 格式数据如何转化到字节数组中byte[]
- webservices里如果只让构造函数中的代码只在初次调用时执行,该怎么写
- 如何动态生成控件!!!!!
- DataGrid中的数据如何分页?我是新手,请讲的清楚一些!
- 我发觉现在很多程序员真的很浮躁
- 请问在我作完删除或修改之后,为什么用鼠标单击Datagrid后说我“索引超出数组范围“。
- 请问谁有WROX的《C#入门经典》的第26、27、28章源代码?
- .Net Remoting 服务器端如何控制连接个数
- outlook插件的部署。。。
(1)使用socket、Tcp等协议建立服务,进行流传输,需要在服务器端和客户端开发两套程序(或服务)。
(2)常用的方式是使用Ftp,就是在服务器端创建ftp服务器,客户端与服务器端进行连接,然后进行传输。希望对你有帮助,有什么问题可以进一步交流。
我开始就是用的FTP 服务器端部署的serv-u 但是最近这段时间 老是上传失败 程序直接卡死 调试又不报错 serv-u 日志显示文件没传完用户就注销了.....高了一天了毫无头绪!
http://www.2cto.com/kf/201205/129940.html
/// 上传文件
/// </summary>
/// <param name="filename"></param>
private string Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
if ( !fileInf.Exists ){
return filename + " 不存在!\n";
}
string uri = ftpURI + fileInf.Name;
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.UsePassive = false; //选择主动还是被动模式
//Entering Passive Mode
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
try
{
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
strm.Close();
fs.Close();
}
catch (Exception ex)
{
return "同步 "+filename+"时连接不上服务器!\n";
//Insert_Standard_ErrorLog.Insert("FtpWeb", "Upload Error --> " + ex.Message);
}
return "";
}
至于服务器端,也很简单,每一个asp.net程序员应该都知道的。
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string serverPath = Server.MapPath("UpLoad"); //获取服务器端目录绝对路径
if (!System.IO.Directory.Exists(serverPath)) //如果不存在该目录
{
System.IO.Directory.CreateDirectory(serverPath); //创建该目录
}
if (FileUpload1.HasFile) //判断是否选择上传的文件
{
int filesize = FileUpload1.PostedFile.ContentLength / 1024 / 1024;//获取上传文件的大小
if (filesize > 8) //如果大于8M
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('只允许上传不大于8兆的文件');", true); //弹出提示信息
return;
}
else //否则
{
//使用SaveAs方法将上传的文件存储到服务器中
FileUpload1.SaveAs(serverPath + "\\" + FileUpload1.FileName);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('上传成功');", true);
}
}
else //如果没有选择文件
{
//弹出提示信息
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请选择文件');", true);
return;
}
请问 我上传时为什么 报错 {System.Net.WebException: 远程服务器返回错误: (550) 文件不可用(例如,未找到文件,无法访问文件)
还可以使用:http://blog.csdn.net/chinacsharper/article/details/19162047