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


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?

  • 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

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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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