java web ftp (ftpwebrequest,如何使用FtpWebRequest(.NET)更改目录?

Mariya Atanasova有一个

blog post,它显示了如何伪造它 – 基本上你必须把目录放在URL上.

我怀疑你可能会因为一个专用的FTP库而变得更好 – 一个不会试图强迫所有东西进入WebRequest做事的方式.我没有亲自使用任何第三方库,但搜索“FTP库.NET”找到了很多候选人.

编辑:jcolebrand(2006年博客链接的可能性)

Many customers ask us how they can use the CWD command with our FtpWebRequest.

The answer is: you cannot use the command directly, but you can modify the uri parameter to achieve the same result.

Let’s say you’re using the following format:

String uri = "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl";

FtpWebRequest Request = (FtpWebRequest)WebRequest.Create(uri);

Request.Method = "LIST";

The above example will bring you to your user’s directory and list all the contents there. Now let’s say you want to go 2 directories backwards and list the contents there (provided your user has permissions to do that). You close the previous FtpWebRequest and issue a new one with this uri

uri = "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/%2E%2E/%2E%2E";

This is equivalent to logging in with your user’s credentials and then using cd ../../

Note: if you try using the ”..” directly without escaping them the uri class will strip them, so "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/../.." is equivalent to "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/"

Now let’s say you want to go to another user’s directory which is one level above the root. If you don’t specify a user name and password it’s equivalent to logging in as anonymous user. Then you issue a new FtpWebRequest with the following uri

"ftp://myFtpUrl/%2F/anotherUserDir"

This is equivalent to logging in as anonymous and then doing

Cd /

cd anotherUserDirectory

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值