1

I am currently able to transfer the file .. but somehow the content is being left out. I think that object is not being returned properly but cannot figure it out.

$folder1 = "<external server>"
$folder2 = "<local path>"

# Get all files under $folder1, filter out directories
$firstFolder = Get-JFSChildItem $folder1 | Where-Object { -not $_.PsIsContainer }

    $firstFolder | ForEach-Object {
    # Check if the file, from $folder1, exists with the same path under $folder2
    If (!(Test-Path($_.FullName.Replace($folder1, $folder2))))
    {
        $fileSuffix = $_.FullName.TrimStart($folder1)
        Write-Host "$fileSuffix is only in folder1"
        Receive-JFSItem $fileSuffix -destination $folder2
    }

}

Error: Receive-JFSItem : No such file; No such file.

Error: Receive-JFSItem <<<< $fileSuffix -destination $folder2

1 Answer 1

1

You are using TrimStart wrongly. TrimStart accepts a set of symbols to trim from the argument, and you expect to trim the folder name as an exact string from its beginning. You should instead replace $folder1 with empty string in $_.fullname.

If (!(Test-Path($_.FullName.Replace($folder1, $folder2))))
{
    $fileSuffix = $_.FullName.Replace($folder1,"")
    Write-Host "$fileSuffix is only in folder1"
    Receive-JFSItem $fileSuffix -destination $folder2
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but content of the files is still not being transferred. Error: Receive-JFSItem : No such file; No such file. Error: + Receive-JFSItem <<<< $fileSuffix -destination $folder2 Error: + CategoryInfo : NotSpecified: (:) [Receive-JFSItem], SftpException Error: + FullyQualifiedErrorId : Rebex.Net.SftpException,MVPSI.Commands.ReceiveJFSItemCommand
If so, read manuals on Receive-JFSItem better, perhaps it demands full name of the file, and you are trying to feed it only base name. Try Receive-JFSItem $_.fullName -destination $folder2, or just $_.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.