久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 FtpWebRequest (.NET) 更改目錄?

How do you change directories using FtpWebRequest (.NET)?(如何使用 FtpWebRequest (.NET) 更改目錄?)
本文介紹了如何使用 FtpWebRequest (.NET) 更改目錄?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

誰能告訴我如何使用 FtpWebRequest 更改目錄?這似乎應(yīng)該是一件容易的事,但我沒有看到它.

編輯

我只是想補(bǔ)充一下...我對 FtpWebRequest 沒有興趣.如果有更好(更簡單)的方式在 .NET 中執(zhí)行 FTP,請告訴我.

<小時>

顯然沒有辦法使用實(shí)時連接來做到這一點(diǎn),您需要更改 uri 以欺騙 ftpwebrequest 使用不同的請求(感謝 Jon).

所以我正在尋找第 3 方客戶...

我嘗試過的一些開源解決方案效果不佳(一直崩潰),但我找到了一個通過我的一些初步測試的開源解決方案(.NET FTP 客戶端).

解決方案

有一個博文,它展示了如何偽造它 - 基本上你必須將目錄放在 URL 上.

我懷疑使用專用的 FTP 庫可能會更好 - 一個不會試圖將所有內(nèi)容都強(qiáng)制轉(zhuǎn)換為 WebRequest 做事方式的庫.我個人沒有為此使用任何 3rd 方庫,而是搜索FTP library .NET".找到很多候選人.


jcolebrand(以防 2006 年博客 linkrot 的可能性)

<塊引用>

許多客戶詢問我們?nèi)绾螌?CWD 命令與我們的 FtpWebRequest 一起使用.

答案是:不能直接使用命令,但是可以修改uri參數(shù)達(dá)到同樣的效果.

假設(shè)您使用以下格式:

String uri = "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl";FtpWebRequest 請求 = (FtpWebRequest)WebRequest.Create(uri);Request.Method =列表";

<塊引用>

以上示例將帶您進(jìn)入用戶目錄并列出其中的所有內(nèi)容.現(xiàn)在假設(shè)您要向后移動 2 個目錄并列出其中的內(nèi)容(前提是您的用戶有權(quán)執(zhí)行此操作).你關(guān)閉之前的 FtpWebRequest 并使用這個 uri 發(fā)出一個新的

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

<塊引用>

這相當(dāng)于使用您的用戶憑據(jù)登錄,然后使用 cd ../../

注意:如果您嘗試直接使用 ".." 而不轉(zhuǎn)義它們,則 uri 類將刪除它們,因此 "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/../.." 等價于 "ftp://myFtpUserName:myFtpUserPassword@myFtpUrl/"

現(xiàn)在假設(shè)您要轉(zhuǎn)到另一個用戶的目錄,該目錄比根目錄高一級.如果您不指定用戶名和密碼,則相當(dāng)于以匿名用戶身份登錄.然后你發(fā)出一個新的 FtpWebRequest 和下面的 uri

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

<塊引用>

這相當(dāng)于匿名登錄然后做

Cd/cd 另一個用戶目錄

Can someone tell me how to change directories using FtpWebRequest? This seems like it should be an easy thing to do, but I'm not seeing it.

EDIT

I just want to add...I don't have my heart set on FtpWebRequest. If there's a better (easier) way to do FTP in .NET please let me know.


Apparently there's no way to do it using a live connection, you need to change the uri to trick ftpwebrequest into using a different request (thanks Jon).

So I'm looking for a 3rd party client...

Some of the open source solutions I tried didn't work too well (kept crashing), but I found one open source solution that's passed some of my preliminary tests (.NET FTP Client).

解決方案

There's a blog post from Mariya Atanasova which shows how you can fake it - basically you have to put the directory on the URL.

I suspect you may be better off with a dedicated FTP library though - one that doesn't try to force everything into the WebRequest way of doing things. I haven't personally used any 3rd party libraries for this, but a search for "FTP library .NET" finds lots of candidates.


Edit: jcolebrand (in case of 2006 blog linkrot possibility)

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

這篇關(guān)于如何使用 FtpWebRequest (.NET) 更改目錄?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 国产亚洲精品综合一区 | 国产一级片一区二区 | 97精品超碰一区二区三区 | 看毛片的网站 | 夜夜操天天操 | 久久精品免费观看 | 亚洲高清av在线 | 免费看91| 91资源在线 | 成人在线视频免费播放 | 免费视频一区二区 | 日韩欧美操 | a视频在线 | 久久国产视频播放 | 亚洲精品国产电影 | 久久成人高清视频 | 热99视频 | 午夜男人视频 | 男人天堂国产 | 亚洲精品一区在线观看 | 国产精品久久久亚洲 | 狠狠色狠狠色综合日日92 | 日操夜操 | 日本中文字幕在线视频 | 国产福利91精品一区二区三区 | 在线免费观看黄色 | 国产精品久久久久aaaa | 午夜精品网站 | 精久久久久 | 九九久久这里只有精品 | 91xxx在线观看 | 日韩一区二区三区av | 美日韩一区二区 | 免费国产网站 | 久久小视频| 天天拍天天操 | 亚洲免费网| 一级毛片免费 | 一级毛片视频在线 | 亚洲综合久久精品 | 欧美 日韩 中文 |