我用FTP类上传文件时只有文件名含有#号它就自动把#号和#号后的文件全删除了 是怎么回事呢
解决方案 »
- 高分求助,DesignSurface中的撤销问题。
- 一键登录163和126邮箱
- 请哪位朋友帮我解决C#中的一个技术问题,谢谢
- C# or java 调用WebService 在不知道其返回值的情况下怎么调方法
- 刷新另外一页的datagird
- 100分送高手!怎样禁止修改已经被其他用户修改的字段?
- 求助。。。TreeView 的Microsoft.Web.UI.WebControls.DLL 在虚拟目录下的一个文件夹下怎么使用?
- 一个简单的C#&socket的问题,请教高手
- 在C#中如何存取ORACLE的BLOB?
- 想完成类似ToolTip的功能,遇到问题~~~~~~~~~
- winform中把图片传到指定的文件夹中怎么写
- ajax初学者求助
http://www.edu.cn/20010830/210045.shtml
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地址和文件名不能为空!请填写地址或者选择文件名!");
}
} private void btn_OpenFileDialog_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = true;//设置属性为多选
openFileDialog.ShowDialog();
foreach (string fName in openFileDialog.FileNames)
{
this.listBox_FileName.Items.Add(fName);
}
} private void btn_Remove_Click(object sender, EventArgs e)
{
for (int i = this.listBox_FileName.Items.Count - 1; i >= 0; i--)
{
if (this.listBox_FileName.SelectedIndices.Contains(i))
{
this.listBox_FileName.Items.RemoveAt(i);
}
}
}