自己写了两个方法,分别用来上传和下载,并在远程服务器上建立了FTP站点.在我本机上跑没问题.但发布到IIS上后,别人来访问时,下载时出现了问题.无法将FTP上的文件下载到客户机上,抛出的错误是没有权限在客户机上建立文件.也就是说登录客户机时的权限问题.请高手给出两个方法用来实现FTP的上传下载(C#.NET,不是WINFORM,是WEB的.)每次只需要传本地保存路径和要下载的文件名即可)

解决方案 »

  1.   

    我有一个类库合你要求,看你能用不,开源的带源代码
    LumiSoft.Net.FTP
    我今天晚上可以传给你,还有我只写了winform的实现代码
    QQ 47332677
    [email protected]
      

  2.   

    补充一下再,要BS的,,,,,,,,,,,,就是想问一下,当我发布到IIS上时,然后在其它客户机上访问IIS上已经发布的WEBSITE,为什么点下载按钮后,文件无法下载到操作的客户机上...老是说被拒绝.是不是有权限问题,WINFORM的肯定是没有问题的.但BS的....是不是都会有这样的问题.客户机用的是XP,服务器是2003.
      

  3.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using Excel = Microsoft.Office.Interop.Excel;namespace MyProject
    {
        public partial class NotifyIconDemo : Form
        {
            private WebClient m_objClient;
            public NotifyIconDemo()
            {
                InitializeComponent();
                lblTotal.Text = "";
                lblDown.Text = "";
                
                m_objClient = new WebClient();
                //注册下载进度改变时所触发的事件
                m_objClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(m_objClient_DownloadProgressChanged);
                //注册下载完成时所触发的事件
                m_objClient.DownloadFileCompleted += new AsyncCompletedEventHandler(m_objClient_DownloadFileCompleted);
               
            }
            /// <summary>
            /// 下载进度处理
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void m_objClient_DownloadProgressChanged(Object sender, DownloadProgressChangedEventArgs e)
            {
                lblTotal.Text = Convert.ToString(e.TotalBytesToReceive);
                lblDown.Text = Convert.ToString(e.BytesReceived);
                progressBar1.Value = e.ProgressPercentage;
            }
            /// <summary>
            /// 下载完成
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void m_objClient_DownloadFileCompleted(Object sender, AsyncCompletedEventArgs e)
            {
                if (e.Error != null)
                {
                    MessageBox.Show("发生错误:" + e.Error.Message);
                    return;
                }
                if (e.Cancelled)
                    MessageBox.Show("下载已被取消");
                else
                    MessageBox.Show("下载已完成");
            }
            /// <summary>
            /// 浏览
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnBrowse_Click(object sender, EventArgs e)
            {
                DialogResult ret = saveFileDialog1.ShowDialog();
                if (ret == DialogResult.OK)
                {
                    txtPath.Text = saveFileDialog1.FileName;
                }        }
            /// <summary>
            /// 设置属性
            /// </summary>
            /// <param name="notifyIcon"></param>
            private void InitNotifyIcon(NotifyIcon notifyIcon)
            {
                notifyIcon.Visible = true;
                notifyIcon.Icon = new Icon("TextFrameThumb11.ico");
                notifyIcon.BalloonTipTitle = "温馨提示";
                notifyIcon.BalloonTipText = "在这里单击右键可以重新打开界面";
                notifyIcon.Text = "NotifyIcon应用示例";
                ContextMenuStrip contextMenu = new ContextMenuStrip();
                ToolStripMenuItem itemShwo = new ToolStripMenuItem();
                itemShwo.Click+=new EventHandler(itemShwo_Click);
                itemShwo.Text = "打开主界面";
                ToolStripMenuItem itemExit = new ToolStripMenuItem();
                itemExit .Click +=new EventHandler(itemExit_Click);
                itemExit.Text = "退出程序";
                contextMenu.Items.Add(itemShwo);
                contextMenu.Items.Add(itemExit);
                notifyIcon.ContextMenuStrip = contextMenu;//设置右键菜单
            }
            /// <summary>
            /// 显示
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void itemShwo_Click(Object sender, EventArgs e)
            {
                this.Show();
            }
            /// <summary>
            /// 退出
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void itemExit_Click(Object sender, EventArgs e)
            {
                Application.Exit();
            }
            /// <summary>
            /// 最小化时隐藏并显示托盘信息
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void FormResize(Object sender, EventArgs e)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Visible = false;
                    this.notifyIcon1.ShowBalloonTip(2000);
                }
            }
            private void NotifyIconDemo_Load(object sender, EventArgs e)
            {
                //MessageBox.Show("aaa");
                this.Resize+=new EventHandler(FormResize);
                InitNotifyIcon(this.notifyIcon1);
            }
            /// <summary>
            /// 开始下载
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnDown_Click(object sender, EventArgs e)
            {
                if (m_objClient.IsBusy)
                {
                    MessageBox.Show("WebClient繁忙");
                    return;
                }
                string sURL = txtUrl.Text.Trim();
                string sPath = txtPath.Text.Trim();
                if (sURL.Length <= 0)
                {
                    MessageBox.Show("请输入多要下载文件的URL.");
                    txtUrl.Focus();
                    return;
                }
                if (sPath.Length<=0)
                {
                    MessageBox.Show("请设置下载文件的保存路径.");
                    txtPath.Focus();
                    return;
                }
                m_objClient.DownloadFileAsync(new Uri(sURL), sPath);
            }
            /// <summary>
            /// 关闭
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnCLose_Click(object sender, EventArgs e)
            {
                if (m_objClient.IsBusy)
                {
                    if(MessageBox.Show (null,"WebClient繁忙,确定要关闭吗?","关闭",MessageBoxButtons.OKCancel,MessageBoxIcon .Question)==DialogResult .OK)
                    {
                        m_objClient.CancelAsync ();
                        this.Close();
                    }
                }
                else
                {
                    this.Close();
                }
            }
        }
    }自己写的,可以看一下!
      

  4.   

    要BS版的,FORM的没问题.要BS版的.....
      

  5.   

    楼上发的是...............真汗......高手啊,BS版的啊,从FTP上下载文件到本地....BS版的!!!!