在C#里怎么把一个文本框里输入的内容保存成一个文件,同时再上传到FTP服务器啊? 在C#里怎么把一个文本框里输入的内容保存成一个文件,同时再上传到FTP服务器啊?他这个FTP服务器不能创建文件,我快晕死了怎么办啊就是跟发邮件一样,只是把文本框里的内容在服务器上保存成一个文件各位大哥大姐救救我吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void Upload(string filename) { FileInfo fileInf = new FileInfo(filename); pubFile File_text = new pubFile("", filename); //string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name; FtpWebRequest reqFTP; try { // 根据uri创建FtpWebRequest对象 reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strURI)); //reqFTP.UsePassive = false; // ftp用户名和密码 reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); //reqFTP.ContentType = "application/x-www-form-urlencoded"; // 默认为true,连接不会被关闭 // 在一个命令之后被执行 //reqFTP.KeepAlive = false; reqFTP.UsePassive = false; // 指定执行什么命令 reqFTP.Method = WebRequestMethods.Ftp.UploadFile; // 指定数据传输类型 reqFTP.UseBinary = true; //reqFTP.EnableSsl = true; // 上传文件时通知服务器文件的大小 reqFTP.ContentLength = fileInf.Length; // 缓冲大小设置为2kb int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // 打开一个文件流 (System.IO.FileStream) 去读上传的文件 FileStream fs = fileInf.OpenRead(); // 把上传的文件写入流 //FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); //File_text.Write(DateTime.Now.ToString() + response.StatusDescription); //File_text.Write(DateTime.Now.ToString() + response.StatusCode.ToString()); Stream strm = null; strm = reqFTP.GetRequestStream(); // 每次读文件流的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); } File_text.WriteErrorLine(DateTime.Now.ToString() + "成功"); // 关闭两个流 strm.Close(); fs.Close(); } catch (Exception ex) { File_text.WriteErrorLine(DateTime.Now.ToString() + "\nUpload Error:" + ex.Message); } } pubFile ,FtpWebRequest都是哪个命名空间里的啊 哥哥啊,我要2003的代码FtpWebRequest是2005里的类啊 just Process.Start("ftp.exe") shrinerain(圣影雨) 是叫你直接调用ftp这个exe要上传?有FileUpload控件啊,直接用不就可以了,为什么要用ftp呢? 电脑流量统计,通过代码如何统计,C#方面的,在线等 c# 怎么对数据库插入和更新后,然后举行判断,成功与否! 一个算法,大家求解一下!谢谢 我...我...就是想知道...那个... ThreadPool里面怎样设置最大线程数字!!! onPrintPage()问题 remoting + call + 反序列化问题 为什么我做的控件在“我的用户控件”中不显示?(急) 如何实现这样的设计 新手求教,groupBox 输入输出流操作时丢失数据的问题 我是新手:关于网络连接的问题
{
FileInfo fileInf = new FileInfo(filename);
pubFile File_text = new pubFile("", filename);
//string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
FtpWebRequest reqFTP;
try
{
// 根据uri创建FtpWebRequest对象
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strURI));
//reqFTP.UsePassive = false;
// ftp用户名和密码
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
//reqFTP.ContentType = "application/x-www-form-urlencoded"; // 默认为true,连接不会被关闭
// 在一个命令之后被执行
//reqFTP.KeepAlive = false;
reqFTP.UsePassive = false;
// 指定执行什么命令
reqFTP.Method = WebRequestMethods.Ftp.UploadFile; // 指定数据传输类型
reqFTP.UseBinary = true;
//reqFTP.EnableSsl = true;
// 上传文件时通知服务器文件的大小
reqFTP.ContentLength = fileInf.Length; // 缓冲大小设置为2kb
int buffLength = 2048; byte[] buff = new byte[buffLength];
int contentLen; // 打开一个文件流 (System.IO.FileStream) 去读上传的文件
FileStream fs = fileInf.OpenRead(); // 把上传的文件写入流
//FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse(); //File_text.Write(DateTime.Now.ToString() + response.StatusDescription);
//File_text.Write(DateTime.Now.ToString() + response.StatusCode.ToString());
Stream strm = null;
strm = reqFTP.GetRequestStream();
// 每次读文件流的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);
}
File_text.WriteErrorLine(DateTime.Now.ToString() + "成功"); // 关闭两个流
strm.Close();
fs.Close();
}
catch (Exception ex)
{
File_text.WriteErrorLine(DateTime.Now.ToString() + "\nUpload Error:" + ex.Message);
}
}