【发布时间】:2023-03-09 16:30:02
【问题描述】:
以下 PowerShell 脚本运行 ftp 命令但返回错误,因为它无法找到绝对源路径(其中包括空格,并且确实将完整路径作为“文件一”和“目标一”。
输出:
/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 中进行哪些更改才能在源和目标中包含这些空格,以便它可以正确返回 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
【问题讨论】:
-
您会尝试其中一个并给我们反馈吗? *
$dest = "e:/Files/Destination One/File\ One"*$dest = "e:/Files/Destination One/File%20One" -
是的,添加转义字符“e:/Files/Destination One/File\ One”有效。但就我而言,我无法更新 dest 变量,因为它是硬编码的。
-
所以如果我没猜错的话,$ftppath 或 $ftpcmd 是唯一可以更改的变量吗?
-
$ftppath = "sftp://$user" + '@' + $server + ':' + $root + '/' + $source.replace(" ","\ ") + ' ' + $dest.Replace(" ","\ ") 这个怎么样?
-
行得通!谢谢@SoufianeMghanen
标签: powershell ftp