psftp上传文件到服务器,使用PsFtp将文件上传到FTP Powershell

我在这个问题上一直在抨击我的大脑,似乎无法修复它。我正在尝试使用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。我也尝试删除变量并使用硬编码路径;我得到了同样的错误。

有什么想法吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值