asp.net 操作ftp 通用代码[测试通过]

简介: 代码如下:   代码 // 建立目录 FtpWebRequest Request = (FtpWebRequest)WebRequest.Create("ftp://113.

代码如下:

 

代码
 
  
// 建立目录
FtpWebRequest Request = (FtpWebRequest)WebRequest.Create( " ftp://113.107.160.135:2121/vadmin.uuu9.com/aaa " );
Request.Credentials
= new NetworkCredential( " wanglei " , @" }}XnJXt4a\7datr " );
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();

 

img_fa0be433d68c8212b2b0b3b1a564ccb1.png
如果本文对你有所帮助,请打赏——1元就足够感动我:)
支付宝打赏 微信打赏
联系邮箱:intdb@qq.com
我的GitHub: https://github.com/vipstone
关注公众号: img_9bde0f31ac4a0eca10b1bd7414b78faf.png


作者: 王磊
出处: http://vipstone.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,请标明出处。

相关文章
|
1月前
|
Java 关系型数据库 数据库连接
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
28 1
|
2月前
|
测试技术
包含用例执行时间的测试报告代码
包含用例执行时间的测试报告代码
|
4月前
com串口通信测试代码
com串口通信测试代码
28 0
|
4月前
|
存储 人工智能 C#
【Unity 3D】C#中数组、集合、栈、队列、哈希表、字典的讲解(附测试代码)
【Unity 3D】C#中数组、集合、栈、队列、哈希表、字典的讲解(附测试代码)
36 0
|
4月前
|
监控 前端开发 JavaScript
如何测试前端代码? 知道 BDD, TDD, Unit Test 么? 知道怎么测试你的前端工程么(mocha, sinon, jasmin, qUnit..)?
如何测试前端代码? 知道 BDD, TDD, Unit Test 么? 知道怎么测试你的前端工程么(mocha, sinon, jasmin, qUnit..)?
74 0
|
3月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
42 0
|
18天前
|
算法 安全 Java
java代码 实现AES_CMAC 算法测试
该代码实现了一个AES-CMAC算法的简单测试,使用Bouncy Castle作为安全提供者。静态变量K定义了固定密钥。`Aes_Cmac`函数接受密钥和消息,返回AES-CMAC生成的MAC值。在`main`方法中,程序对给定的消息进行AES-CMAC加密,然后模拟接收ECU的加密结果并进行比较。如果两者匹配,输出"验证成功",否则输出"验证失败"。辅助方法包括将字节转为16进制字符串和将16进制字符串转为字节。
|
1月前
|
测试技术 数据库 Python
python测试代码(二)
python测试代码(二)
19 0
|
1月前
|
Java 测试技术
单元测试编写可测试代码
单元测试编写可测试代码
19 2
|
2月前
|
存储 测试技术
统计测试结果的代码实现接昨天
统计测试结果的代码实现接昨天

热门文章

最新文章