Automation Robot框架:从远程位置获取多个文件到目标目录

Automation Robot框架:从远程位置获取多个文件到目标目录,automation,robotframework,Automation,Robotframework,有了Robot框架,有没有办法将多个文件从一个目录复制到本地目录 我在SSHLibrary中看到Get File关键字。 它支持复制多个文件,但在指定目标目录时不起作用 如果只指定一个要复制的文件,则target directory参数有效。 如果在源文件(例如/path/*.ext)中指定了多个文件,并且指定了目标目录,则会出现以下错误: Cannot copy multiple source files to one destination file 若我删除目标目录作为参数,那个么所有文

有了Robot框架,有没有办法将多个文件从一个目录复制到本地目录

我在SSHLibrary中看到
Get File
关键字。 它支持复制多个文件,但在指定目标目录时不起作用

如果只指定一个要复制的文件,则target directory参数有效。
如果在源文件(例如/path/*.ext)中指定了多个文件,并且指定了目标目录,则会出现以下错误:

Cannot copy multiple source files to one destination file
若我删除目标目录作为参数,那个么所有文件都会被复制到执行目录,这是我想要避免的

这是一个存根:

Get Remote files 
     [Arguments]    ${HOST} ${ROOT_PASS}    ${TARGET_DIR}
     Open Connection  ${HOST}
     Login  ${ROOT_USER}    ${ROOT_PASS}
     Log To Console     Logged in to server
     SSHLibrary.Get File    //*.ext ${TARGET_DIR}
     Log To Console     Files copied to ${TARGET_DIR}

我假设SSHLibrary文档中有一个bug

从get文件的文档中:

1. If the destination is an existing file, the source file is downloaded over it. 2. If the destination is an existing directory, the source file is downloaded into it. Possible file with the same name is overwritten. 3. If the destination does not exist and it ends with the path separator of the local operating system, it is considered a directory. The directory is then created and the source file is downloaded into it. Possible missing intermediate directories are also created. 4. If the destination does not exist and does not end with the local path separator, it is considered a file. The source file is downloaded and saved using that file name, and possible missing intermediate directories are also created. 1.如果目标是现有文件,则源文件将通过该文件下载。 2.如果目标是现有目录,则源文件将下载到其中。可能具有相同名称的文件被覆盖。 3.如果目标不存在且以本地操作系统的路径分隔符结尾,则将其视为目录。然后创建目录并将源文件下载到其中。还创建了可能缺少的中间目录。 4.如果目标不存在且未以本地路径分隔符结尾,则将其视为文件。使用该文件名下载和保存源文件,并创建可能缺少的中间目录。 我假设对于(2)和对于(3)一样,目标文件夹上也需要一个尾随/字符


您还可以尝试指向一个不存在的文件夹(该文件夹将在现场创建)-再次使用尾随/

这是一个测试robot脚本,它成功地将所有文件从远程机器中获取到本地机器中的目标目录

诀窍是在目标目录末尾加/(使用${/}表示平台独立,比如C:${/}temp${/}告诉windows上的C:/temp/,下面给出的linux示例)


如果您想从其他文件夹中的文件夹下载多个文件,那么可以使用SSH库的
**获取目录**
**列出目录**
方法

  • 创建关键字“从远程服务器获取文件夹并复制”,该关键字包含两个参数:源文件夹路径和目标文件夹路径

    ***Keywords***
    Get Folder from remote server and copy it
        [Documentation]    Used to copy Folder within Folder from some source location(can be from local or remote machine) to destination location(can be into local or remote machine)
        [Arguments]    ${source}    ${destination}
        Log To Console    \n--------------------------------Copying Result folder from remote machine to local machine      
        Get Directory    ${source}    ${destination}
        @{directories}    List Directories In Directory    ${source}
        : FOR    ${dir}    IN    @{directories}
        \    ${currentSrc}    Catenate    SEPARATOR=     ${source}    ${dir}           
        \    ${currentDestination}    Catenate    SEPARATOR=     ${destination}    ${dir}
        \    Get Directory    ${currentSrc}    ${currentDestination}
    
  • 在测试用例中调用这个关键字

    *** Test Cases ***
    Copy multiple files    
        Get Folder from remote server and copy it locally    ${Resultsource}  ${Resultdestination}
    

  • 指定目录时,如何执行?在windows上,目录是否以“/”(或“\”结尾)?目标目录存在吗?我正在windows上工作。目标目录被指定为绝对路径(不以/结尾),并且它已经存在。您能否显示调用关键字的确切方式?我正在使用SSHLibrary从远程服务器获取文件。我明白了。这将有助于了解您如何调用关键字。在没有看到实际代码的情况下很难发现代码中的bug。是的,我正在使用SSHLibrary。在尝试了所有这些组合之后,我发布了这个问题,这些组合都不起作用。。现在,我首先将所需文件复制到ROBOT的本地工作目录,然后使用OperatingSystem库中的“move files”关键字将它们移动到我的dest目录。robotframework.org/robotframework/latest/libraries/
    *** Test Cases ***
    Copy multiple files    
        Get Folder from remote server and copy it locally    ${Resultsource}  ${Resultdestination}