asp.net 怎么检测一个ftp ip 用户名 密码 是否正确?ftp服务器正常。本人不会asp.net,请各位高手尽量给出全的代码,谢谢!asp 貌似是无法实现的不写组件的话

解决方案 »

  1.   

    给你一个C#的事例吧using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Net;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private string ftpServerIP="";
            private string ftpUserID="";
            private string ftpPassword="";        private void button1_Click(object sender, EventArgs e)
            {        }
            
            private void Download(string filePath, string fileName)
            {
                FtpWebRequest reqFTP;
                try
                {
                    FileStream outputStream = new FileStream((filePath + "\\" + fileName), FileMode.Create);
                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP+fileName));
                    reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
                    reqFTP.UseBinary = true;
                    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                    Stream ftpStream = response.GetResponseStream();
                    long cl = response.ContentLength;
                    int bufferSize = 2048;
                    int readCount;
                    byte[] buffer = new byte[bufferSize];
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                    while (readCount > 0)
                    {
                        outputStream.Write(buffer, 0, readCount);
                        readCount = ftpStream.Read(buffer, 0, bufferSize);
                    }
                    ftpStream.Close();
                    outputStream.Close();
                    response.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }        }
        }}
      

  2.   

    使用在程序中调用FTP控件测试下连接
      

  3.   

    http://blog.sina.com.cn/s/blog_5607239a0100c2jy.html