在 Powershell 中使用 Pro CLI 时,如果执行“放置”时文件存在,我需要覆盖提示。我有以下内容,但仍然收到提示,这是正确的吗?
$scriptContent = @"
open sftp://${ftpUser}:${ftpPass}@${ftpHost}:22
lcd $localDirectory
option cli.prompt.file_exists:6
"@
Get-ChildItem -Path $localDirectory -Recurse | ForEach-Object {
if ($_.PSIsContainer) {
$relativePath = $_.FullName.Substring($localDirectory.Length) -replace "\\", "/"
$remoteDirPath = "./$relativePath"
$scriptContent += "mkdir $remoteDirPath" + "`n"
} else {
$localFile = $_.FullName -replace "\\", "/"
$relativePath = $_.DirectoryName.Substring($localDirectory.Length) -replace "\\", "/"
$remoteFilePath = if ($relativePath) { "./$relativePath/" + $_.Name } else { "./" + $_.Name }
$scriptContent += "nput `"$localFile`" `"$remoteFilePath`"" + "`n"
}
}
我还尝试使用该选项仅在文件较新或大小不同时才放置文件,但这似乎也不起作用。
$scriptContent += "put -e:size_newer `"$localFile`" `"$remoteFilePath`"" + "`n"
对于任何感兴趣的人,将带有 put 命令的行更改为固定它
$scriptContent += "put --exists size_newer `"$localFile`" `"$remoteFilePath`"" + "`n"