【发布时间】: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..." 会起作用,但是使用这种方法就不行了。
如果您运行该命令,您会注意到它肯定是由于引号问题。
你有什么线索吗?
谢谢
【问题讨论】:
-
如果您在引用时遇到问题,那么使用
-EncodedCommand将是一个很好的方法:stackoverflow.com/questions/6295957/… -
不错的方法,我会试试的。
标签: windows powershell ftp upload quote