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

將整個文件夾上傳到 FTP 的 PowerShell 腳本

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

問題描述

限時送ChatGPT賬號..

我正在使用 PowerShell 腳本將整個文件夾的內容上傳到 FTP 位置.我對 PowerShell 很陌生,只有一兩個小時的經驗.我可以很好地上傳一個文件,但找不到一個好的解決方案來處理文件夾中的所有文件.我假設一個 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()

請注意,上面的代碼不會遞歸到子目錄中.

Note that the above code does not recurse into subdirectories.

如果您需要更簡單的解決方案,則必須使用 3rd 方庫.

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()

上面的代碼確實是遞歸的.

The above code does recurse.

請參閱 https://winscp.net/eng/docs/library_session_putfiles

(我是 WinSCP 的作者)

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

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

相關文檔推薦

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 令牌授權不起作用)
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(如何獲取守護進程或服務器到 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(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 日韩在线观看网站 | 人人干天天干 | 美日韩免费视频 | 伊人精品在线 | 日韩专区中文字幕 | 国产一级电影在线观看 | 狠狠操狠狠干 | 成人欧美一区二区三区视频xxx | 亚洲精品久久久久中文字幕欢迎你 | 欧美激情综合色综合啪啪五月 | 91色站 | 日韩av啪啪网站大全免费观看 | 97成人免费 | 国产精品一区二区免费 | 国产欧美精品一区 | 久久久久久亚洲 | 久久久2o19精品 | 欧美日韩亚洲一区 | 日韩av一区二区在线观看 | 日韩综合一区 | 秋霞精品| 在线高清免费观看视频 | 欧美一区二区精品 | 日韩视频在线免费观看 | 中文字幕在线观看一区 | 欧美成年视频 | 成人欧美一区二区三区在线观看 | 可以看黄的视频 | 精品欧美乱码久久久久久 | 久久久久久久国产精品视频 | 久久国产精品偷 | 精精久久| 亚洲成人一区 | 国产综合久久 | 日日噜噜噜夜夜爽爽狠狠视频, | 久久乐国产精品 | 亚洲国产精品久久久久 | 美女天天操 | 男女羞羞在线观看 | 欧美在线a | 欧美成视频|