我有一个项目,我试图自动化 . 我需要在计算机上运行一些负载测试,在此期间我需要有一个常量进出FTP流量 . 我一直在尝试编写一个Powershell脚本来做到这一点,但一直在做空 . 我每次都可以下载文件,但上传总是失败 . 我还需要确保我的循环机制是正确的 .

我需要这个来下载并上传一个文件,直到我告诉它停止 . 这是脚本 .

$FTPServer = '172.20.2.124'
$FTPUsername = 'ftp'
$FTPPassword = 'ftpTransfers'
$FTPSecurePassword = ConvertTo-SecureString -String $FTPPassword -asPlainText -Force
$FTPCredential = New-Object System.Management.Automation.PSCredential($FTPUsername,$FTPSecurePassword)
$Path = '/'
$LocalPath = 'C:\Downloads'

#Open session
Set-FTPConnection -Credentials $FTPCredential -Server $FTPServer -Session MySession -UseBinary -KeepAlive 
$Session = Get-FTPConnection -Session MySession 

#download file
Get-FTPItem -Path /File1.mxf -LocalPath $LocalPath -Overwrite -Session $Session | out-null

#Upload the file
Add-FTPItem -LocalPath $LocalPath/File1.mxf -Path $Path -Overwrite -Session $Session | out-null

do {
response = Read-Host "repeat?"
}
while ($response -eq "Y")

这是我每次尝试使用脚本上传时出现的错误 . 我试图找出如何关闭流但我没有运气 .

Add-FTPItem:使用“0”参数调用“GetRequestStream”的异常:“对象引用未设置为对象的实例 . ”在C:\ Powershell Scripts \ FTPUploadandDownload.ps1:22 char:1 Add-FTPItem -LocalPath $ LocalPath / File1.mxf -Path $ Path -Overwrite -Session ... ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 〜/ ~~~~~~~~~~~~~~~分类信息:未指定:(:) [Write-Error],WriteErrorException FullyQualifiedErrorId:Microsoft.PowerShell.Commands.WriteErrorException,Add-FTPItem

任何帮助将不胜感激,我对这个级别的powershell相当新 .