ASP.Net FTP 的使用方式

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();


    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值