Skip to content

Copying binary file to the target host using Add-Content command taking very long time #160

@mannukalra

Description

@mannukalra

Trying to copy a binary file(40 mb) to the target host using Add-Content command taking very long time because of the command length limit. Any suggestions if there is a way to stream.

Below is the code:

long size = Files.size(path);
final int BUFFER_SIZE = 4096; // 4KB
if(size > BUFFER_SIZE){
    try (InputStream inputStream = new FileInputStream(inputFile)) {
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesRead = -1;
        int offset = 0;
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            var content = new String(Base64.getEncoder().encode(buffer));
            tool.executeCommand("powershell -Command \"Add-Content '"+targetFile+"' -Value ([System.Convert]::FromBase64String('"+content+"')) -Encoding Byte\"");
        }

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions