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

C# 使用 FTP 上傳整個目錄

C# Upload whole directory using FTP(C# 使用 FTP 上傳整個目錄)
本文介紹了C# 使用 FTP 上傳整個目錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我要做的是在 C# (C Sharp) 中使用 FTP 上傳網站.所以我需要上傳一個文件夾中的所有文件和文件夾,保持它的結構.我正在使用這個 FTP 類:http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class 用于實際上傳.

What I'm trying to do is to upload a website using FTP in C# (C Sharp). So I need to upload all files and folders within a folder, keeping its structure. I'm using this FTP class: http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class for the actual uploading.

我得出的結論是,我需要編寫一個遞歸方法,遍歷主目錄的每個子目錄并上傳其中的所有文件和文件夾.這應該將我的文件夾復制到 FTP.問題是......我不知道如何編寫這樣的方法.我以前寫過遞歸方法,但我是 FTP 部分的新手.

I have come to the conclusion that I need to write a recursive method that goes through every sub-directory of the main directory and upload all files and folders in it. This should make an exact copy of my folder to the FTP. Problem is... I have no clue how to write a method like that. I have written recursive methods before but I'm new to the FTP part.

這是我目前所擁有的:

private void recursiveDirectory(string directoryPath)
    {
        string[] filePaths = null;
        string[] subDirectories = null;

        filePaths = Directory.GetFiles(directoryPath, "*.*");
        subDirectories = Directory.GetDirectories(directoryPath);

        if (filePaths != null && subDirectories != null)
        {
            foreach (string directory in subDirectories)
            {
                ftpClient.createDirectory(directory);
            }
            foreach (string file in filePaths)
            {
                ftpClient.upload(Path.GetDirectoryName(directoryPath), file);
            }
        }
    }

但它遠未完成,我不知道如何繼續.我敢肯定,比我更需要知道這一點!在此先感謝:)

But its far from done and I don't know how to continue. I'm sure more than me needs to know this! Thanks in advance :)

哦……如果它也報告它的進度就好了:)(我正在使用進度條)

Ohh and... It would be nice if it reported its progress too :) (I'm using a progress bar)

可能還不清楚...如何使用 FTP 上傳包含所有子目錄和文件的目錄?

It might have been unclear... How do I upload a directory including all sub-directories and files with FTP?

推薦答案

問題解決了!:)

好的,所以我設法編寫了方法 myslef.如果有人需要,請隨時復制:

Problem Solved! :)

Alright so I managed to write the method myslef. If anyone need it feel free to copy:

private void recursiveDirectory(string dirPath, string uploadPath)
    {
        string[] files = Directory.GetFiles(dirPath, "*.*");
        string[] subDirs = Directory.GetDirectories(dirPath);

        foreach (string file in files)
        {
            ftpClient.upload(uploadPath + "/" + Path.GetFileName(file), file);
        }

        foreach (string subDir in subDirs)
        {
            ftpClient.createDirectory(uploadPath + "/" + Path.GetFileName(subDir));
            recursiveDirectory(subDir, uploadPath + "/" + Path.GetFileName(subDir));
        }
    }

效果很好:)

這篇關于C# 使用 FTP 上傳整個目錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 亚洲女人天堂网 | 久久精品一区二区 | 成人深夜小视频 | 免费看a| 欧美国产精品一区二区三区 | 国产美女一区二区 | 国产精品久久久久久久久免费丝袜 | 亚洲国产精品suv | 久久综合狠狠综合久久综合88 | 91国在线 | 一区视频 | av在线播放免费 | 久久久久综合 | 精品伦精品一区二区三区视频 | 在线观看黄色电影 | 亚洲国产成人精品女人久久久 | 中文字幕亚洲精品在线观看 | 新91| 青青伊人久久 | 一区二区三区四区在线免费观看 | 国产二区视频 | 亚洲一区二区久久久 | 北条麻妃99精品青青久久主播 | 美女黄18岁以下禁止观看 | 丝袜 亚洲 欧美 日韩 综合 | 成人午夜激情 | 韩日有码 | 日韩中文字幕视频在线 | 一区二区视频 | 91丨九色丨国产在线 | 欧美日韩高清在线一区 | 久久亚洲欧美日韩精品专区 | 99精品久久 | 性一交一乱一透一a级 | 不卡在线一区 | av网站免费 | av黄色免费 | 欧美 日韩 中文 | 九九热免费在线观看 | 午夜精品福利视频 | 美日韩中文字幕 |