【问题标题】:How to write a FTP File Upload script using powershell in background in one line如何在后台使用powershell在一行中编写FTP文件上传脚本
【发布时间】:2017-11-02 12:38:28
【问题描述】:

存在许多使用 PowerShell 将文件上传到远程服务器的方法。

我正在使用System.Net.WebClient 对象来执行该任务,并使用Start-Process 命令在后台执行此操作。

我的目标是通过cmd.exe 仅使用一行命令来执行该任务。

使用以下命令:

PowerShell.exe Start-Process -FilePath "PowerShell.exe" -ArgumentList "-c `"$uploadFile='PATH'; $linkFTP='ftp://user:pass@IP/file'; $client=New-Object -TypeName System.Net.WebClient; $URI=New-Object -TypeName System.Uri -ArgumentList $ftp; $client.UploadFile($URI,$uploadFile)`" "

此命令可确保通过cmd.exe,您将使用 PowerShell 在后台执行 FTP 文件上传。直接使用脚本文件而不是使用-FilePath "PowerShell.exe" -ArgumentList "-c..." 会起作用,但是使用这种方法就不行了。

如果您运行该命令,您会注意到它肯定是由于引号问题。

你有什么线索吗?

谢谢

【问题讨论】:

标签: windows powershell ftp upload quote


【解决方案1】:
Start-Process -FilePath "PowerShell.exe" -ArgumentList "-c {$uploadFile='PATH'; $linkFTP='ftp://user:pass@IP/file'; $client=New-Object -TypeName System.Net.WebClient; $URI=New-Object -TypeName System.Uri -ArgumentList $ftp; $client.UploadFile($URI,$uploadFile)} "

编辑:

注意:$ftp变量未定义

【讨论】:

  • 您使用方括号来尝试解决问题。但是,我尝试使用您的解决方案,但发生错误,提示 ArgumentList 缺少参数
  • 您的$ftp 变量未在任何地方定义,因此-ArgumentListNew-Object -TypeName System.Uri -ArgumentList 将为空。
猜你喜欢
  • 1970-01-01
  • 2010-10-30
  • 2012-04-23
  • 2017-08-26
  • 1970-01-01
  • 1970-01-01
  • 2011-02-23
  • 2016-09-24
  • 1970-01-01
相关资源
最近更新 更多