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

在 PowerShell 中自動化安全 FTP 的最佳方法是什么

What#39;s the best way to automate secure FTP in PowerShell?(在 PowerShell 中自動化安全 FTP 的最佳方法是什么?)
本文介紹了在 PowerShell 中自動化安全 FTP 的最佳方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

I'd like to automate the FTP download of a database backup file using PowerShell. The file name includes the date so I can't just run the same FTP script every day. Is there a clean way to do this built into PowerShell or using the .NET framework?

I want to use a secure FTP session.

解決方案

After some experimentation I came up with this way to automate a secure FTP download in PowerShell. This script runs off the public test FTP server administered by Chilkat Software. So you can copy and paste this code and it will run without modification.

$sourceuri = "ftp://ftp.secureftp-test.com/hamlet.zip"
$targetpath = "C:hamlet.zip"
$username = "test"
$password = "test"

# Create a FTPWebRequest object to handle the connection to the ftp server
$ftprequest = [System.Net.FtpWebRequest]::create($sourceuri)

# set the request's network credentials for an authenticated connection
$ftprequest.Credentials =
    New-Object System.Net.NetworkCredential($username,$password)

$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::DownloadFile
$ftprequest.UseBinary = $true
$ftprequest.KeepAlive = $false

# send the ftp request to the server
$ftpresponse = $ftprequest.GetResponse()

# get a download stream from the server response
$responsestream = $ftpresponse.GetResponseStream()

# create the target file on the local system and the download buffer
$targetfile = New-Object IO.FileStream ($targetpath,[IO.FileMode]::Create)
[byte[]]$readbuffer = New-Object byte[] 1024

# loop through the download stream and send the data to the target file
do{
    $readlength = $responsestream.Read($readbuffer,0,1024)
    $targetfile.Write($readbuffer,0,$readlength)
}
while ($readlength -ne 0)

$targetfile.close()

I found a lot of helpful information at these links

  • FTP downloads: encoding problems
  • Simple FTP demo application
  • Very Simple FTP Client

If you want to use an SSL connection you need to add the line

$ftprequest.EnableSsl = $true

to the script before you call GetResponse(). Sometimes you may need to deal with a server security certificate that is expired (like I unfortunately do). There is a page at the PowerShell Code Repository that has a code snippet to do that. The first 28 lines are the most relevant for the purposes of downloading a file.

這篇關于在 PowerShell 中自動化安全 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 令牌授權不起作用)
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屋-程序員軟件開發技
.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 超時)
主站蜘蛛池模板: 国产精品一区二区三级 | 午夜免费视频 | 国产在线精品一区二区三区 | 一级在线观看 | 中文字幕高清一区 | 色网在线看| 欧美激情va永久在线播放 | 亚洲一区二区三区 | 97久久精品午夜一区二区 | 成人免费视屏 | 欧美日本久久 | 欧美午夜精品理论片a级按摩 | 国产视频久 | 在线成人 | 九九天堂网| 性色av一区二区三区 | 国产中文视频 | 久草中文在线 | 在线观看av中文字幕 | 欧产日产国产精品视频 | 一区二区精品 | 一色一黄视频 | 亚洲第一福利网 | 日韩三级 | 免费看色 | 亚洲精品久久久久久久久久久久久 | 精品网站999www | 欧美99久久精品乱码影视 | 中文字幕视频在线 | 欧美精品在欧美一区二区少妇 | 国产精品99久久久久久久久久久久 | 黑人精品 | 99亚洲精品 | 久久精品亚洲欧美日韩久久 | 国产精品久久久久久婷婷天堂 | 亚洲一区二区中文字幕 | 欧美日韩国产一区二区 | 久久中文字幕在线 | 日韩中字幕 | 成人亚洲网站 | 成人av一区 |