Topic "Problem with Getfiles path incorrect when using powershell"

Author Message
kwslavens
[View user's profile]

Joined: 2013-06-12
Posts: 3
Location: US MO
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.
Advertisements
kwslavens
[View user's profile]

Joined: 2013-06-12
Posts: 3
Location: US MO
UPDATE:

This is happening on both Powershell 2.0 and 3.0.

Version 5.1.5 of winscp and automation library.
kwslavens
[View user's profile]

Joined: 2013-06-12
Posts: 3
Location: US MO
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.
Caine
[View user's profile]

Joined: 2013-01-04
Posts: 1
Location: PAC NW, USA
You need to add invoke to the script line:

$session.GetFiles.invoke($SourceFile,$TargetFolder).Check()
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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 http://stackoverflow.com/. Please post a link here, if you do.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License