久久久久久久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 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 日韩在线小视频 | 一区二区三区国产好 | 色中文在线| 国产精品久久久亚洲 | 欧美一级在线视频 | 99视频在线免费观看 | 久久久久国产精品 | 国产精品美女久久久久aⅴ国产馆 | 日韩中文字幕一区二区三区 | 国产一区二区精品在线 | 日本精品免费在线观看 | 91精品国产自产在线老师啪 | 成人h片在线观看 | 久久av一区二区三区 | 亚洲一区视频在线 | 日韩一级不卡 | 精产国产伦理一二三区 | 一级毛片视频在线 | 国产精品一区三区 | 久热国产精品 | 亚洲在线视频 | 欧美a在线| 亚洲视频在线观看一区二区三区 | 亚洲午夜精品一区二区三区 | 人操人免费视频 | 黄色网址免费在线观看 | 国产高清免费视频 | 男女免费在线观看视频 | 欧美区日韩区 | 黄网站涩免费蜜桃网站 | 国产在线一区二区 | 玖玖综合网 | 黄色片视频 | 国产高清免费视频 | 玖玖视频 | 久久精品久久久久久 | 午夜小影院 | 国产精品污www一区二区三区 | 精品伊人 | 一区二区三区四区国产 | 污书屋 |