Powershell and SFTP.exe

1

Is it possible to pipe the contents of a folder on an SFTP site to a local file similar to window sinnate ftp.exe program where the syntax:

dir /MainDir/SubDir c:\test\ftp\CurrentContents.txt

but the same syntax does not work with SFTP.exe. I need to be able to process one file name at a time in a powershell script and I can see no way to pass file names from the SFTP.exe program to the powershell script and back without being able to parse a text file with directory contents.

If anyone has any ideas or suggestions please let me know. thanks rp

user194104

Posted 2013-01-30T20:31:50.603

Reputation: 11

Answers

1

I use Rebex's .NET components for FTPS & SFTP in my C# programs & PowerShell scripts. I find it much easier than slinging around external programs that weren't really designed to interact smoothly with scripts & other applications.

Edit: Since money is an issue, have you tried using one of the utilities bundled with PuTTY?

alroc

Posted 2013-01-30T20:31:50.603

Reputation: 407

I appreciate the answer but, as a public agency with no funds for additional software, a 350$ price tag is out of league. – user194104 – 2013-01-31T16:25:00.513

At $20/hour (to make the math easy), if you spend 2 days fighting with sftp.exe and haven't gotten it to work yet, you've already spent about $350 of the agency's funds and still don't have a solution. I understand what you're saying, but time does have a dollar value attached to it. See my edit for another suggestion. – alroc – 2013-01-31T18:21:03.773

0

The Push-FTP function from PowerShell Pipeworks does this, but not as perfectly as I would like. I will make the required edits to support seamless pipelining in a few days. It also provides a progress bar during uploads.

Here's an example:

Push-Ftp -Path c:\Example -Include *.aspx

Start-Automating

Posted 2013-01-30T20:31:50.603

Reputation: 111

0

I'm using putty psftp which works great with powershell.

Usage:

let's create $tempContentFile containing ftp commands in ASCII encoding

$tempContentFile = "$($workdir)\temp_get.txt"
$tempContent = "get -r /root/home/someuser/filestoDownload C:\temp\DownloadedFiles"
$out = out-file -filepath $tempContentFile -inputobject $tempContent -encoding ASCII;

First we need to ensure that remote server SSL certificate is accepted/storred locally

$out = echo Y|.\plink.exe -v -ssh $($attribute_IP) -l $($attribute_user) -pw $($attribute_password) -batch exit 2>&1

Than psftp command itself:

$out = .\psftp.exe $($attribute_IP) -l $($attribute_user) -pw $($attribute_password) -b $tempContentFile

Laky

Posted 2013-01-30T20:31:50.603

Reputation: 101