本文介紹了FTPClient如何刪除目錄?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我想刪除 FTP 中的一個(gè)文件夾.
I want to delete a folder in FTP.
FTPClient
對(duì)象可以刪除嗎?
推薦答案
FtpWebRequest 提供刪除操作.這是實(shí)現(xiàn)這一目標(biāo)的一段代碼:
FtpWebRequest provides the Delete action. Here is a piece of code to achieve that :
FtpWebRequest reqFTP = FtpWebRequest.Create(uri);
// Credentials and login handling...
reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
string result = string.Empty;
FtpWebResponse response = reqFTP.GetResponse();
long size = response.ContentLength;
Stream datastream = response.GetResponseStream();
StreamReader sr = new StreamReader(datastream);
result = sr.ReadToEnd();
sr.Close();
datastream.Close();
response.Close();
它應(yīng)該適用于文件和目錄.確實(shí),請(qǐng)檢查您是否擁有正確的權(quán)限.
It should work on files and directories. Indeed, please check that you have the right permissions.
此外,當(dāng)文件夾不為空時(shí),您無(wú)法刪除它們.您必須遞歸遍歷它們才能刪除內(nèi)容.
Also, you could not delete folders while they are not empty. You must traverse them recursively to delete content before.
由于權(quán)限問(wèn)題引發(fā)的異常并不總是很清楚...
The exceptions thrown due to right permissions problems are not always very clear...
這篇關(guān)于FTPClient如何刪除目錄?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!