麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

.netftp上傳文件方法

2019-11-14 14:20:28
字體:
供稿:網(wǎng)友

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Text;
using System.Configuration;

namespace DlnOffice.general.netdisk
{
public partial class fileupload2 : System.Web.UI.Page
{

//這三個常量是從webconfig獲取
PRivate string ftpServerip = ConfigurationManager.AppSettings["ftpServerIP"];
private string ftpUserID = ConfigurationManager.AppSettings["ftpUserID"];
private string ftpPassWord = ConfigurationManager.AppSettings["ftpPassword"];
protected void Page_Load(object sender, EventArgs e)
{

}
protected void LinkButton1_Click(object sender, EventArgs e)
{
up_FTP(FileUpload1);
//up_FTP(FileUpload2);
Response.Write("<script>alert('完成');window.location.href ='fileupload2.aspx'</script>");

//else
//{
// Response.Write("<script>alert('未選擇文件');</script>");
// return;
//}
}

public void up_FTP(FileUpload fu)
{
string AppPath = (base.Request.QueryString["parent_folder"] != null) ? base.Request.QueryString["parent_folder"].ToString() : "/信息科/常用軟件";
if (string.IsNullOrEmpty(AppPath))
{
base.Response.Redirect("index.aspx");
return;
}
//文件上傳地址根目錄,這里通過IIS架設(shè)本地主機(jī)為FTP服務(wù)器
//string FileSaveUri = @"ftp://127.0.0.1/";
string FileSaveUri = @"ftp://" + ftpServerIP + AppPath + "/";
//FTP用戶名密碼,就是本機(jī)的用戶名密碼
string ftpUser = ftpUserID;
string ftpPassWord = ftpPassword;
Stream requestStream = null;
Stream fileStream = null;
FtpWebResponse uploadResponse = null;//創(chuàng)建FtpWebResponse實(shí)例uploadResponse
//Btn_Upload.
if (fu.HasFile)
{
//獲取文件長度
int FileLength = fu.PostedFile.ContentLength;
//限制上傳文件最大不能超過1G
if (FileLength < 1024 * 1024 * 1024)
{
try
{

//格式化為URI
Uri uri = new Uri(FileSaveUri + Path.GetFileName(fu.PostedFile.FileName));
FtpWebRequest uploadRequest = (FtpWebRequest)WebRequest.Create(uri);//創(chuàng)建FtpWebRequest實(shí)例uploadRequest
uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;//將FtpWebRequest屬性設(shè)置為上傳文件
uploadRequest.Credentials = new NetworkCredential(ftpUser, ftpPassWord);//認(rèn)證FTP用戶名密碼
requestStream = uploadRequest.GetRequestStream();//獲得用于上傳FTP的流
byte[] buffer = new byte[FileLength];
fileStream = fu.PostedFile.InputStream;//截取FileUpload獲取的文件流,作為上傳FTP的流
fileStream.Read(buffer, 0, FileLength);
requestStream.Write(buffer, 0, FileLength);//將buffer寫入流
requestStream.Close();
uploadResponse = (FtpWebResponse)uploadRequest.GetResponse();//返回FTP服務(wù)器響應(yīng),上傳完成
//上傳成功

}
catch (Exception ex)
{
//無法上傳
Response.Write("<script>alert('無法上傳');</script>");
return;
}
finally
{
if (uploadResponse != null)
uploadResponse.Close();
if (fileStream != null)
fileStream.Close();
if (requestStream != null)
requestStream.Close();
}
}//end if #FileLength#
else
{
//上傳文件過大
Response.Write("<script>alert('上傳文件過大,文件不得超過1G');</script>");
return;
}
}//end if #FileUpload.HasFile#
else
{
//未選擇文件
return;
}
}
}
}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产精品二区高清在线 | 成人免费看毛片 | 精品乱码久久久久 | 久久国产经典 | 久久精品无码一区二区日韩av | 久久91精品 | 狠狠干五月天 | 精品1 | 毛片在线视频免费观看 | 线观看免费完整aaa 欧美在线一级 | 久久国产精 | 久久精品女人天堂av | 黄色毛片视频在线观看 | 国产精品久久久久久久久久电影 | 成人三级免费电影 | 久久久国产精品网站 | 九九热免费观看 | 国产成年人网站 | 天堂亚洲一区 | 国产精品刺激对白麻豆99 | 久久久www成人免费精品 | 中文字幕在线观看www | 狠狠干91 | 99精品视频在线导航 | a视频在线免费观看 | 中文字幕视频在线播放 | 国产日韩a | 羞羞的网址 | 久久精品网 | 日韩精品中文字幕一区二区三区 | 日韩精品久久久久久久九岛 | 一级黄色免费观看视频 | 精品国产一二区 | 午夜视频福利 | 成人毛片在线免费看 | 黄网站在线播放视频免费观看 | 国产高潮失禁喷水爽到抽搐视频 | 一区二区美女视频 | 日日草天天干 | 久久久久久麻豆 | 国产一区二区三区四区精 |