Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Problem with Getfiles path incorrect when using powershell

This definitely looks like a problem with your PowerShell syntax. I'm not that familiar with PowerShell to help you and it seems out of scope of this forum anyway. Consider asking on https://stackoverflow.com/. Please post a link here, if you do.
Caine

You need to add invoke to the script line:

$session.GetFiles.invoke($SourceFile,$TargetFolder).Check()
kwslavens

Another UPDATE:

This seems to only happen in the situation where the variables are being passed in as parameters to a function.

$SourceFile = "/Extract/SCTM.xlsx"
$TargetFolder = "e:\File-Hold\"
$session.GetFiles($SourceFile,$TargetFolder).Check()

Works fine...


function DOWNLOAD($SourceFile,$TargetFolder)
{
$session.GetFiles($SourceFile,$TargetFolder).Check()
}

DOWNLOAD("/Extract/SCTM.xlsx","e:\File-Hold\")


This on the other hand results in the problem I posted. Where the path for source and destination are combined.
kwslavens

UPDATE:

This is happening on both Powershell 2.0 and 3.0.

Version 5.1.5 of winscp and automation library.
kwslavens

Problem with Getfiles path incorrect when using powershell

I'm working on a simple download of specific files and I've run into this issue.

This works.
$session.GetFiles("/Extract/SCTM.xlsx","e:\File-Hold\").Check()


This Does not.
$SourceFile = "/Extract/SCTM.xlsx"
$TargetFolder = "e:\File-Hold\"
$session.GetFiles($SourceFile,$TargetFolder).Check()

The problem in the log seems to be that the path doesn't resolve as expected.

> 2013-06-12 11:37:10.120 Script: get -nopermissions -preservetime -transfer="binary" -- "/Extract/SCTM.xlsx e:\File-Hold\" ""

It seems to be adding the 2 paths together as a source file and setting the targetfolder to be blank.

I've tried a lot of different ideas to get the variable paths to work but always comes back incorrect in the logs giving error
Can't get attributes of file '/Extract/SCTM.xlsx e:\File-Hold\'.


Any idea's why this is happening. I'm running the code on a 2012 server running powershell 3.0.