SFTP with WinSCP

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf SFTP with WinSCP

  • Creator
    Topic
  • #51269
    Carl Duff
    Participant

      Does anyone have a UPoC that calls WinSCP (and passes parameters) that they would be willing to share?

      Thanks in advance for any assistance.

      Carl

    Viewing 0 reply threads
    • Author
      Replies
      • #69468
        garry r fisher
        Participant

          Hi Carl,

          Rather than pass parameters, use the scripting option with WinSCP. I have over 30 (very simple) interfaces that use WinSCP to SFTP files to various systems using this method to generate scripts on the fly from a Tclproc.

          This is how I do it:

          # Write script

                         echo “Writing script file for $systm ($envir $systm)”

                         set ofh [open $script w]

                         puts $ofh “# Automatically answer all prompts negatively not to stall”

                         puts $ofh “# the script on errors”

                         puts $ofh “option batch on”

                         puts $ofh “# Disable overwrite confirmations that conflict with the previous”

                         puts $ofh “option confirm off”

                         puts $ofh “lcd “D:/interfaces/to oeo/$envir/$systm/inbound/””

                         puts $ofh “# connect using session”

                         puts $ofh “open server”

                         puts $ofh “# Force binary mode transfer”

                         puts $ofh “option transfer binary”

                         puts $ofh “# Download file to the local directory”

                         foreach fname $files {

                             set fname [file tail $fname]

                             puts $ofh “put $fname “./to oeo/$envir/$systm/inbound/$fname””

                         }

                         puts $ofh “# Disconnect”

                         puts $ofh “close”

                         puts $ofh “# Exit WinSCP”

                         puts $ofh “exit”

                         close $ofh

          # Call WinSCP

                         echo “Calling WinSCP [clock format [clock scan seconds] -format %d/%m/%Y:%H:%M]”

                         if {[catch {exec winscp.com /script=$systm.txt} errmsg]} {

                             echo “There was a problem with the SFTP connection ($errmsg)”

          The ‘open server’ command simply opens a connection to a saved WinSCP session called server.

          One thing to watch out for is getting winscp.com on the correct path in Cloverleaf.

          Regards

          Garry

      Viewing 0 reply threads
      • The forum ‘Cloverleaf’ is closed to new topics and replies.