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

Petr

Please look at WinSCP Download page, section WinSCP 5.0.6 beta, it is called .NET assembly / COM library.
Jonboy

What???? cant find your stuff

Petr wrote:

Please look at WinSCP 5.0.6 beta, it is called .NET assembly / COM library.



I cannot find any WinSCP 5.0.6. beta nor can I find the winscpXXXautomation.zip Please folks let us get or act together.
clt

powershell example

I beg you to add powershell example. Thank you!
Petr

Please look at WinSCP 5.0.6 beta, it is called .NET assembly / COM library.
danis

Hi Prikryl,
I just wanted to Download the .NET assembly.


It is written:

WinSCP .NET assembly is available in a separate package named winscpXXXautomation.zip on WinSCP download page. Follow the .NET assembly/COM library link.


In the Download section I can't find it anywhere.. could you help me?
martin

Re: SFTP Download with WinSCP and PowerShell - just to show

We have just released WinSCP .NET assembly which may make your script way simpler.
https://winscp.net/eng/docs/library
We plan to add a powershell example later.
danis

SFTP Download with WinSCP and PowerShell - just to show

Hello all,
I'd like to show you my short script for downloading files via SFTP from a Server to a local machine.

It is working good now, but I am new to PowerShell and WinSCP (saw it the first time last week..) - so maybe you got some ideas to make it better..

#FTP Connection Parameters

$username = "yourUserName"
$password = ""
[bool]$usepassword = $false #false if PPK File used, otherwise true
$hostkey = "ssh-rsa 1024 00:00:00:00:00:00:00:00:00:00:00:00:00:00:0:00" #fingerprint of the FTP Server
$WinSCPPath = "C:\Program Files (x86)\WinSCP\"
$ppkpath = "H:\Scripts\private_key.ppk"
$UserFolderFTP_from = "/from"
$UserFolderFTP_to = "to"
$server = "ServerHere"

$LocalFolder_Temp = "H:\Scripts\Temp\"
$logFolder = "H:\Logs\"
$logfile = "FTPLog.txt"

function DownloadFiles
   {
      $date = Get-Date -format "yyyy-MM-dd HH:mm:ss.000"
      out-file $logFolder$logfile -append   -encoding "ASCII" -InputObject ". $date - Download started"
      #Create Command for WinSCP to open Connection.
      $Script = '"option batch abort" '
        $Script += ' "option confirm off" '
      if ($usepassword)
         {
         $Script += ' "open sftp://' + "$username:$password@$server -hostkey=" + '""' + $hostkey + '"""'
         }
      else
         {
         $Script += ' "open sftp://' + "$username@$server -privatekey=$ppkpath -hostkey=" + '""' + $hostkey + '"""'
         }
        $Script += ' "cd ' + $UserFolderFTP_from + '"'
      $Script += ' "option transfer binary"'       
        $Script += ' "get  -delete * ' + $LocalFolder_Temp + '"'       
        $Script += " close"
        $Script += " exit"
      
      Set-Location -Path $WinSCPPath
      .\WinSCP.com /log=$logFolder$logfile /command $Script
      $date = Get-Date -format "yyyy-MM-dd HH:mm:ss.000"
      out-file $logFolder$logfile -append   -encoding "ASCII" -InputObject ". $date - Download Ended"
   }
   
function UploadFiles
   {
      $date = Get-Date -format "yyyy-MM-dd HH:mm:ss.000"
      out-file $logFolder$logfile -append -encoding "ASCII"   -InputObject ". $date - Upload started"
      #Create Command for WinSCP to open Connection.
      $Script = '"option batch abort"'
        $Script += ' "option confirm off"'
        if ($usepassword)
         {
         $Script += ' "open sftp://' + "$username:$password@$server -hostkey=" + '""' + $hostkey + '"""'
         }
      else
         {
         $Script += ' "open sftp://' + "$username@$server -privatekey=$ppkpath -hostkey=" + '""' + $hostkey + '"""'
         }
        $Script += ' "cd ' + $UserFolderFTP_to + '"'
      $Script += ' "lcd ' + $LocalFolder_TransDat + '"'
      $Script += ' "option transfer binary"'       
      $Script += ' "put -delete * -nopermissions -nopreservetime"'
        $Script += " close"
        $Script += " exit"
      
      Set-Location -Path $WinSCPPath
      .\WinSCP.com /log=$logFolder$logfile /command $Script
      $date = Get-Date -format "yyyy-MM-dd HH:mm:ss.000"
      out-file $logFolder$logfile -append   -encoding "ASCII" -InputObject ". $date - Upload Ended"
   }
   
DownloadFiles
UploadFiles


Regards,