Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

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?

share|improve this answer
    
I appreciate the answer but, as a public agency with no funds for additional software, a 350$ price tag is out of league. –  user194104 Jan 31 '13 at 16:25
    
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 Jan 31 '13 at 18:21

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
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.