資料來源:http://www.dotblogs.com.tw/puma/archive/2008/03/16/1659.aspx

記得using System.Net

c#範例...完整程式碼如下:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class ftp_CS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //建立目錄
        FtpWebRequest Request = (FtpWebRequest)WebRequest.Create("ftp://111.11.11.11:1234/C/puma/test2");
        Request.Credentials = new NetworkCredential("id", "pwd");
        Request.Method = WebRequestMethods.Ftp.MakeDirectory;
        Request.Timeout = (60000 * 1); //60000 * 1,表示1分鐘
        FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
        Response.Close();

        //修改檔案名稱
        FtpWebRequest Request = (FtpWebRequest)WebRequest.Create("ftp://111.11.11.11:1234/C/puma/ssa.txt");
        Request.Credentials = new NetworkCredential("id", "pwd");
        Request.Method = WebRequestMethods.Ftp.Rename;
        Request.Timeout = (60000 * 1); //60000 * 1,表示1分鐘
       Request.RenameTo = "NewName.txt";
        FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
        Response.Close();

        //修改目錄名稱
        FtpWebRequest Request = (FtpWebRequest)WebRequest.Create("ftp://111.11.11.11:1234/C/puma/test");
        Request.Credentials = new NetworkCredential("id", "pwd");
        Request.Method = WebRequestMethods.Ftp.Rename;
        Request.Timeout = (60000 * 1); //60000 * 1,表示1分鐘
        Request.RenameTo = "test2";
        FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
        Response.Close();

        //移除檔案
        FtpWebRequest Request = (FtpWebRequest)WebRequest.Create("ftp://111.11.11.11:1234/C/puma/NewName.txt");
        Request.Credentials = new NetworkCredential("id", "pwd");
        Request.Method = WebRequestMethods.Ftp.DeleteFile;
        Request.Timeout = (60000 * 1); //60000 * 1,表示1分鐘
        FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
        Response.Close();

        //移除目錄
        FtpWebRequest Request = (FtpWebRequest)WebRequest.Create("ftp://111.11.11.11:1234/C/puma/test2");
        Request.Credentials = new NetworkCredential("id", "pwd");
        Request.Method = WebRequestMethods.Ftp.RemoveDirectory;
        Request.Timeout = (60000 * 1); //60000 * 1,表示1分鐘
        FtpWebResponse Response = (FtpWebResponse)Request.GetResponse();
        Response.Close();
    }
}

創作者介紹

歡迎~ 程式設計 學生 作業 專題製作 程式外包 家教...

goodlucky 發表在 痞客邦 PIXNET 留言(0) 人氣()