如何上傳大於2GB的文件到我的FTP服務器使用PowerShell,我使用下面的函數不能上傳文件大於2 GB,通過FTP - PowerShell的
# Create FTP Rquest Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($Username, $Password)
$FTPRequest.UseBinary = $true
$FTPRequest.Timeout = -1
$FTPRequest.KeepAlive = $false
$FTPRequest.ReadWriteTimeout = -1
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = [System.IO.File]::ReadAllBytes(「$LocalFile」)
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
try{
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
# Cleanup
$Run.Close()
$Run.Dispose()
} catch [System.Exception]{
'Upload failed.'
}
我得到這個錯誤同時上傳。
Exception calling "ReadAllBytes" with "1" argument(s): "The file is too long.
This operation is currently limited to supporting files less than 2 gigabytes
in size."
+ $FileContent = [System.IO.File]::ReadAllBytes(「$LocalFile」)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
我已經使用其他功能,但結果卻是如此緩慢的上傳速度就像是沒有比大文件分割成塊會高於50KB/s的 希望有一個解決方案,其他
的[Powershell的讀取塊文件(可能的複製http://stackoverflow.com/問題/ 39345335/powershell-read-file-in-chunk) – sodawillow
我將檢查出現在.. – Vagho
'$ FileStream = [System.IO.File] :: OpenRead(「$ LocalFil E」); $ FTPRequest.ContentLength = $ FileStream.Length; $ Run = $ FTPRequest.GetRequestStream(); $ FileStream.CopyTo($運行); $ Run.Close(); $ FileStream.Close();' – PetSerAl