当前位置:首页 > 服务器 > 正文

asp上传文件到服务器(asp上传文件到服务器上)

本篇文章给大家谈谈asp上传文件到服务器,以及asp上传文件到服务器上对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

如何通过ASP代码,将其它电脑上的文件拷贝到服务器上?

貌似思路有点问题啊

文件上传到服务器一般就3个途径

在服务器运行ftp服务,用户用ftp客户端上传。

通过网页上传文件到服务器。

把文件上传到邮箱,网盘等第三方服务器。再到服务器登录第三方服务器下载

直接把客户的文件复制到服务器不现实

asp.net中上传文件到远程FTP服务器指定目录下,求大神帮助,小弟不胜感激

private string ftpServerIP = "服务器ip";//服务器ip

private string ftpUserID = "ftp的用户名";//用户名

private string ftpPassword = "ftp的密码";//密码

//filename 为本地文件的绝对路径

//serverDir为服务器上的目录

private void Upload(string filename,string serverDir)

{

FileInfo fileInf = new FileInfo(filename);

string uri = string.Format("ftp://{0}/{1}/{2}", ftpServerIP,serverDir,fileInf.Name);

FtpWebRequest reqFTP;

// 根据uri创建FtpWebRequest对象

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));

// ftp用户名和密码

req = new NetworkCredential(ftpUserID, ftpPassword);

// 默认为true,连接不会被关闭

// 在一个命令之后被执行

req = false;

// 指定执行什么命令

req = WebRequestMethods.;

// 指定数据传输类型

req = true;

// 上传文件时通知服务器文件的大小

req = fileInf.Length;

// 缓冲大小设置为2kb

int buffLength = 2048;

byte[] buff = new byte[buffLength];

int contentLen;

// 打开一个文件流 (System.IO.FileStream) 去读上传的文件

FileStream fs = fileInf.OpenRead();

try

{

// 把上传的文件写入流

Stream strm = req;

// 每次读文件流的2kb

contentLen = fs.Read(buff, 0, buffLength);

// 流内容没有结束

while (contentLen != 0)

{

// 把内容从file stream 写入 upload stream

strm.Write(buff, 0, contentLen);

contentLen = fs.Read(buff, 0, buffLength);

}

// 关闭两个流

strm.Close();

fs.Close();

}

catch (Exception ex)

{

// MessageBox.Show(ex.Message, "Upload Error");

Response.Write("Upload Error:" + ex.Message);

}

}

调用方法

string filename = "D:\\test.txt"; //本地文件,需要上传的文件

string serverDir = "img"; //上传到服务器的目录,必须存在

Upload(filename,serverDir);

asp.net中文件如何上传到服务器上

{ } protected void Button1_Click(object sender, EventArgs e){if (this.filepost.PostedFile.FileName == ""){Response.Write("上传文件不能为空!");return;}try{string Path = Server.MapPath("upload/");//设置服务器端路径 string filePath = this.filepost.PostedFile.FileName;//获取客户端实际路径 string fileName = filePath.Substring(filePath.LastIndexOf("\\")+1);//获取文件名称 string serverPath = Path + fileName;//上传的文件保存到服务器端的路径 System.Text.StringBuilder buider = new System.Text.StringBuilder();//上传的文件信息:可变字符串 buider.Append("上传文件的类型:"+this.filepost.PostedFile.ContentType.ToString()+""); buider.Append("客户端文件地址:"+this.filepost.PostedFile.FileName+""); buider.Append("上传文件名称:"+fileName); buider.Append("上传文件的扩展名:"+filePath.Substring(fileName.LastIndexOf(".")+1)); buider.Append("上传文件的大小:"+this.filepost.PostedFile.ContentLength/1024+"k"+""); if (System.IO.File.Exists(serverPath)){Response.Write("这个文件在服务器上已经存在,请不要重复上传!");return;}string str = fileName.Substring(fileName.LastIndexOf(".")+1);//获取文件后缀名 if (str == "jpg" || str == "rar" || str == "ppt"){Response.Write("对不起,该类型文件不能被上传!");return;}if (this.filepost.PostedFile.ContentLength 2048){Response.Write("对不起,文件不能超过2K");return;}this.filepost.PostedFile.SaveAs(serverPath);//上传保存文件

asp上传文件到服务器的代码怎么写?

html

head

meta http-equiv="Content-Type" content="text/html; charset=gb2312"

title无标题文档/title

/head

body

%

'On Error Resume Next

Response.Expires=0

if Request.TotalBytes then

set a=createobject("adodb.stream")

a.Type=1

a.Open

a.write Request.BinaryRead(Request.TotalBytes)

a.Position=0

b=a.Read

c=chrB(13)chrB(10)

d=clng(instrb(b,c))

e=instrb(d+1,b,c)

set f=createobject("adodb.stream")

f.type=1

f.open

a.Position=d+1

a.copyto f,e-d-3

f.Position=0

f.type=2

f.CharSet="GB2312"

g=f.readtext

f.Close

h=mid(g,instrRev(g,"\")+1,e)

i=instrb(b,cc)+4

j=instrb(i+1,b,leftB(b,d-1))-i-2

if j 1 then

set f =nothing

set a =nothing

response.write "未选择要上传的文件a href='?'重新上传/a"

response.end

end if

f.Type=1

f.Open

a.Position=i-1

a.CopyTo f,j

h = Mid(h, InStrRev(h, "filename=""") + 10) '这是我帮你添加的,文件名的获取没有正确

f.SaveToFile server.mappath("/EXCEL/" h),2

f.Close

set f=Nothing

a.Close

set a=Nothing

'response.write "a href="Server.URlEncode(h)""h"/a"

end if

If Err.number 0 Then

response.Write err.number

response.Write err.Description

Response.End

End If

%

script language="javascript"

function checkupload() {

if (document.upload_form.fe.value == "") {

alert("未选择要上传的文件");

return false;

}

}

/script

form name="upload_form" enctype="multipart/form-data" method="post" onsubmit="return(checkupload())"

input type="file" name="fe"/

input type="submit" value="上传" name="B1"/

/form

/body

/html

asp上传文件到服务器的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于asp上传文件到服务器上、asp上传文件到服务器的信息别忘了在本站进行查找喔。

取消
扫码支持 支付码