powershell - 创建可能部分存在于 WinSCP 409 冲突的目录结构

标签 powershell winscp winscp-net

我使用 WinSCP + Powershell 自动将 Jenkins 的构建结果传输到我们的共享服务器,以便 QA 和开发团队可以轻松访问。

需要WinSCP,因为它只能通过Webdav 协议(protocol)传输。别担心!!

假设我需要创建的远程服务器上的目录是

MyProduct/BuildOutput/bin

现在,如果我执行以下命令 a 且文件夹结构完全丢失,则它可以完美运行。

$session.CreateDirectory("MyProduct/BuildOutput/bin")

但是,如果说“MyProduct/BuildOutput”结构已经存在,但缺少“bin”,则 WinSCP 会给出 409 冲突错误。

有没有办法创建一个已经部分存在的完整目录结构,而无需编写复杂的程序来执行此操作?

最佳答案

WinSCP CreateDirectory方法不支持创建整个目录结构。只是单个目录。您必须自己构建该结构。试试这个方法:

    [Array]$dir = 'hello/this/is/test/directory/structure' -split '/'
    $path = [System.String]::Empty
    for ($i=0; $i-lt $dir.Count; $i++){
        if ($i -lt $dir.Count){$path+= $dir[$i] + '/'}
        $session.CreateDirectory($path)
    }

关于powershell - 创建可能部分存在于 WinSCP 409 冲突的目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52951369/

相关文章:

powershell - 从 PowerShell 执行外部命令不接受参数

bash - 如果程序失败,powershell 脚本将停止(如 bash `set -o errexit` )

c# - 在 WinSCP .NET 程序集中包含和排除文件掩码

powershell - MS Flow - "Get-manager"在我的批准流程中不起作用

powershell - 使用 PowerShell 列出带有标记名和标记值的所有 Azure 资源

batch-file - 带有用户名和密码的 WinSCP 脚本文件

regex - 为什么在使用WinSCP .NET程序集时此SSH主机 key 指纹与模式不匹配

PowerShell 和 WinSCP 脚本检查 SFTP 远程目录中是否有超过 4 个文件

ssh - WinSCP .NET 库 : Connect to SFTP server without specifying SSH host key fingerprint

bash - 使用WinSCP在freeSSHD服务器上运行命令失败并显示 “Your shell is probably incompatible with the application (BASH is recommended)”