在这个问题上,我一直在绞尽脑汁,无法解决这个问题 . 我正在尝试使用PSFTP将文件上传到FTP .
我正在使用的脚本:
#------------------------------------------------------
#local variables
$ftp_server = "SERVERNAME"
$ftp_path = "/FTPPATH/PATH"
$local = "C:\ftp\"
$local_in = Join-Path $local "In"
$local_out = Join-Path $local "Out"
$session = "my_ftp_session"
# set up credentials object
$username = "FFandP"
$password = Get-Content "$local_out\Credentials.txt" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password
Set-FTPConnection -Server $ftp_server -Credentials $cred -Session $session -KeepAlive -confirm -UseBinary
Get-ChildItem -Path $local_out |
% {
$ftp_file = "$ftp_path/$($_.Name)" # determine item fullname
Add-FTPItem -Path $ftp_file -LocalPath $_.FullName -Session $session -
}
# -------------------------------------------------
我收到的错误:
Add-FTPItem : Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (550) File
unavailable (e.g., file not found, no access)."
At line:22 char:1
+ Add-FTPItem -Path $ftp_file -LocalPath $_.FullName -Session $session
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-FTPItem
我试过自己运行Add-FTPitem命令,但是我得到了同样的错误 .
我可以使用FileZilla上传到FTP . 我也尝试删除变量并使用硬编码路径;我犯了同样的错误 .
有任何想法吗?
3 回答
@Josh的评论中的答案为我解决了这个问题 . 使用-Overwrite参数运行Add-FTPItem .
我花了一点时间来弄清楚这个问题,但这是我的解决方案(我有同样的问题) .
使用Add-FTPItem时,-Path参数必须 not 包含文件名本身 .
所以在你的例子中它应该是:
文件名将添加到远程FTP路径 . 如果您不想使用相同的名称,则必须先在本地重命名文件,然后再远程重命名 .
改变块
到一行