以下PowerShell脚本运行ftp命令但返回错误,因为无法找到绝对源路径(包括空格并且确实采用完整路径为" File One“和”Destination One" 。
输出:
/usr/bin/lftp -c \"mirror --only-missing --verbose sftp://jason@10.1.1.1:/e:/Files/File One e:/Files/Destination One/File One\"
Access failed: No such file (e:/Files/File)
每个变量的值都是硬编码的,因此无法更改。在这种情况下,$ ftppath或$ ftpcmd需要在source和dest中包含这些空格所需的更改,因此它可以正确返回ftpcmd。有人可以帮忙吗?
脚本:
# these values are hardcoded and cannot be modified
$root = "/e:/Files"
$source = "File One"
$dest = "e:/Files/Destination One/File One"
$user = "jason"
$server = "10.1.1.1"
# ftp command
$ftppath = "sftp://$user" + '@' + $server + ':' + $root + '/' + $source + ' ' + $dest
$ftpcmd = '/usr/bin/lftp -c \"mirror --only-missing --verbose ' + "$ftppath"+'\"'
$ftpcmd
Invoke-Expression -command $ftpcmd
答案 0 :(得分:0)
所以我想你可以像使用它一样使用它:
# these values are hardcoded and cannot be modified
$root = "/e:/Files"
$source = "File One"
$dest = "e:/Files/Destination One/File One"
$user = "jason"
$server = "10.1.1.1"
# ftp command
$ftppath = "sftp://$user" + '@' + $server + ':' + $root + '/' + $source + ' ' + $dest
$ftpcmd = '/usr/bin/lftp -c \"mirror --only-missing --verbose ' + "$ftppath"+'\"'
$ftpcmd
Invoke-Expression -command $ftpcmd.replace(" ", "\ ")
答案 1 :(得分:0)
```壳
$ ftppath =" sftp:// $ user" +' @' + $ server +':' + $ root +' /' + $来源+' ' + $ dest
```
替换为this,使用quote wrap $ dest
```壳
$ ftppath =" sftp:// $ user" +' @' + $ server +':' + $ root +' /' + $来源+' ' +" $ {dest}"
```