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

將整個(gè)文件夾上傳到 FTP 的 PowerShell 腳本

PowerShell Script to upload an entire folder to FTP(將整個(gè)文件夾上傳到 FTP 的 PowerShell 腳本)
本文介紹了將整個(gè)文件夾上傳到 FTP 的 PowerShell 腳本的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我正在使用 PowerShell 腳本將整個(gè)文件夾的內(nèi)容上傳到 FTP 位置.我對(duì) PowerShell 很陌生,只有一兩個(gè)小時(shí)的經(jīng)驗(yàn).我可以很好地上傳一個(gè)文件,但找不到一個(gè)好的解決方案來處理文件夾中的所有文件.我假設(shè)一個(gè) foreach 循環(huán),但也許有更好的選擇?

I'm working on a PowerShell script to upload the contents of an entire folder to an FTP location. I'm pretty new to PowerShell with only an hour or two of experience. I can get one file to upload fine but can't find a good solution to do it for all files in the folder. I'm assuming a foreach loop, but maybe there's a better option?

$source = "c:	est"
$destination = "ftp://localhost:21/New Directory/"
$username = "test"
$password = "test"
# $cred = Get-Credential
$wc = New-Object System.Net.WebClient
$wc.Credentials = New-Object System.Net.NetworkCredential($username, $password)

$files = get-childitem $source -recurse -force
foreach ($file in $files)
{
    $localfile = $file.fullname
    # ??????????
}
$wc.UploadFile($destination, $source)
$wc.Dispose()

推薦答案

循環(huán)(甚至更好的遞歸)是在 PowerShell(或一般的 .NET)中本地執(zhí)行此操作的唯一方法.

The loop (or even better a recursion) is the only way to do this natively in PowerShell (or .NET in general).

$source = "c:source"
$destination = "ftp://username:password@example.com/destination"

$webclient = New-Object -TypeName System.Net.WebClient

$files = Get-ChildItem $source

foreach ($file in $files)
{
    Write-Host "Uploading $file"
    $webclient.UploadFile("$destination/$file", $file.FullName)
} 

$webclient.Dispose()

請(qǐng)注意,上面的代碼不會(huì)遞歸到子目錄中.

Note that the above code does not recurse into subdirectories.

如果您需要更簡(jiǎn)單的解決方案,則必須使用 3rd 方庫(kù).

If you need a simpler solution, you have to use a 3rd party library.

例如使用 WinSCP .NET 程序集:

Add-Type -Path "WinSCPnet.dll"
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.ParseUrl("ftp://username:password@example.com/")

$session = New-Object WinSCP.Session
$session.Open($sessionOptions)

$session.PutFiles("c:source*", "/destination/").Check()

$session.Dispose()

上面的代碼確實(shí)是遞歸的.

The above code does recurse.

請(qǐng)參閱 https://winscp.net/eng/docs/library_session_putfiles

(我是 WinSCP 的作者)

這篇關(guān)于將整個(gè)文件夾上傳到 FTP 的 PowerShell 腳本的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)證并跨請(qǐng)求保留自定義聲明)
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)用時(shí) Azure KeyVault Active Directory AcquireTokenAsync 超時(shí))
主站蜘蛛池模板: 久久精品国产亚洲 | 日韩亚洲一区二区 | 成人在线视频一区二区三区 | 一区二区中文字幕 | 久草影视在线 | 噜噜噜噜狠狠狠7777视频 | 国产欧美视频一区二区三区 | 成人av高清 | heyzo在线 | 欧美午夜激情在线 | 欧美日韩视频在线 | 自拍视频精品 | 成人国产精品视频 | 免费在线观看毛片 | 久久精品99 | 亚洲一区二区视频 | 91久久精品一区二区二区 | 日韩成人影院在线观看 | 国产一区二区三区四区 | 久草色视频| 亚洲a视频 | 亚洲精品久久久久久一区二区 | 国产 日韩 欧美 在线 | 色在线免费 | 亚洲二区视频 | 国产精品一区一区 | 精品久久久久久亚洲精品 | 精品亚洲永久免费精品 | 久久久久国产精品一区二区 | 亚洲精选久久 | 99视频免费在线观看 | 精品乱码一区二区 | 天天躁日日躁狠狠的躁天龙影院 | 午夜视频在线 | 毛片在线看片 | 日韩精品一区二区三区中文字幕 | 在线免费观看视频你懂的 | 国产高清免费视频 | 中文字幕亚洲一区二区va在线 | 91精品久久久久久久久中文字幕 | 情侣酒店偷拍一区二区在线播放 |