欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

powershell Ftp 脚本

程序员文章站 2022-04-29 15:54:07
...

 

Powershell Ftp 上传:

 

$ftp = [System.Net.FtpWebRequest]::Create("ftp://hostdomain/filename")

$ftp = [System.Net.FtpWebRequest]$ftp

$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile

$ftp.Credentials = new-object System.Net.NetworkCredential("UserName","Password")

$ftp.UseBinary = $true

$ftp.UsePassive = $true

$content = [System.IO.File]::ReadAllBytes("The file path to be upload in local computer")

$ftp.ContentLength = $content.Length

$rs = $ftp.GetRequestStream()

$rs.Write($content, 0, $content.Length)

$rs.Close()

$rs.Dispose()