如何上传大于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