上传文件问题? 遍历listbox中的文件名,每取一个上传一次,直到上传结束 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void UpLoad(string fileName) { FileInfo fileInfo = new FileInfo(fileName); string uri = "ftp://" + ftpServerIP + "/" + fileInfo.Name; FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));// 根据uri创建FtpWebRequest对象 reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);//用户名和密码 reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.UploadFile;// 指定执行什么命令 reqFTP.UseBinary = true; // 指定数据传输类型 reqFTP.ContentLength = fileInfo.Length;// 上传文件时通知服务器文件的大小 int buffLength = 2048;// 缓冲大小设置为2kb byte[] buff = new byte[buffLength]; int contentLen; FileStream fs = fileInfo.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) { MessageBox.Show(ex.Message, "Upload Error "); } } private void but_UpLoad_Click(object sender, EventArgs e) { if (this.txt_FTPAddress.Text != "" && this.listBox_FileName.Text != "") { ftpServerIP = this.txt_FTPAddress.Text; ftpUserID = this.txt_User.Text; ftpPassword = this.txt_Pwd.Text; this.UpLoad(this.listBox_FileName.Text); MessageBox.Show("文件上传成功!"); } else { MessageBox.Show("FTP地址和文件名不能为空!请填写地址或者选择文件名!"); } }这样的话 我的UpLoad方法是不是要改下呢? 改成下面的private void but_UpLoad_Click(object sender, EventArgs e) { if (this.txt_FTPAddress.Text != "" && this.listBox_FileName.Text != "") { ftpServerIP = this.txt_FTPAddress.Text; ftpUserID = this.txt_User.Text; ftpPassword = this.txt_Pwd.Text;foreach (string itemValue in listBox1.Items) { this.UpLoad(itemValue); } MessageBox.Show("文件上传成功!"); } else { MessageBox.Show("FTP地址和文件名不能为空!请填写地址或者选择文件名!"); } } 看这里http://topic.csdn.net/u/20100427/11/a8e71a24-fa93-41db-8a2d-14cc59d59400.html deknight 我想问你下 我这样上传的时候有个问题 就是 我上次文件的时候文件名带有#号的话 上传成功后他就把#号和#号后的所有文件名删除! 这个是什么原因呢? 带#号被删应该是FTP端的操作吧,具体不清楚,可能跟它的命令有冲突? deknight : 现在还有个问题就是 我想上传到指定的FTP文件路径 应该怎么处理呢? 遍历listbox使用ftpwebrequest 等实现文件上传foreach (object obj in this.listBox1.Items){ } Frm_Main.SendKeys.Send("{TAB}"); 的问题 word转tiff问题 winform具有鼠标穿透功能后,怎样响应鼠标双击事件 引用的问题 结构赋值与类赋值的差别? 关于第三方开发平台,言者有分! 有人开发过品质统计方面的软件吗?都是用什么控件生成图表(特别是复杂的图表)的? 如何让水晶报表能打印标签呢? 持续了三个月的问题,竞没一个人回答!!!!! 帮忙看一下 请教啊 关于VS2005打开时出现网络http://localhost/管理系统/管理系统.csproj不存在 如何通过删除按钮删除gridview选中行
{
FileInfo fileInfo = new FileInfo(fileName); string uri = "ftp://" + ftpServerIP + "/" + fileInfo.Name; FtpWebRequest reqFTP; reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));// 根据uri创建FtpWebRequest对象 reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);//用户名和密码 reqFTP.KeepAlive = false; reqFTP.Method = WebRequestMethods.Ftp.UploadFile;// 指定执行什么命令 reqFTP.UseBinary = true; // 指定数据传输类型 reqFTP.ContentLength = fileInfo.Length;// 上传文件时通知服务器文件的大小 int buffLength = 2048;// 缓冲大小设置为2kb byte[] buff = new byte[buffLength]; int contentLen; FileStream fs = fileInfo.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)
{
MessageBox.Show(ex.Message, "Upload Error ");
}
} private void but_UpLoad_Click(object sender, EventArgs e)
{
if (this.txt_FTPAddress.Text != "" && this.listBox_FileName.Text != "")
{
ftpServerIP = this.txt_FTPAddress.Text;
ftpUserID = this.txt_User.Text;
ftpPassword = this.txt_Pwd.Text;
this.UpLoad(this.listBox_FileName.Text);
MessageBox.Show("文件上传成功!");
}
else
{
MessageBox.Show("FTP地址和文件名不能为空!请填写地址或者选择文件名!");
}
}这样的话 我的UpLoad方法是不是要改下呢?
{
if (this.txt_FTPAddress.Text != "" && this.listBox_FileName.Text != "")
{
ftpServerIP = this.txt_FTPAddress.Text;
ftpUserID = this.txt_User.Text;
ftpPassword = this.txt_Pwd.Text;
foreach (string itemValue in listBox1.Items)
{
this.UpLoad(itemValue);
}
MessageBox.Show("文件上传成功!");
}
else
{
MessageBox.Show("FTP地址和文件名不能为空!请填写地址或者选择文件名!");
}
}
http://topic.csdn.net/u/20100427/11/a8e71a24-fa93-41db-8a2d-14cc59d59400.html
我想问你下 我这样上传的时候有个问题 就是 我上次文件的时候文件名带有#号的话 上传成功后他就把#号和#号后的所有文件名删除! 这个是什么原因呢?
现在还有个问题就是 我想上传到指定的FTP文件路径 应该怎么处理呢?
foreach (object obj in this.listBox1.Items)
{
}