2

I am trying to connect to an SFTP server via software called WinSCP which is a Secure FTP client, I can script it to work by sending keys and doing it in a psuedo unattended mode, but the Server has to have a user logged in to send the keys, I need WinSCP to logon and transfer the files like a service where the console doesn't launch.

I have tried following the Tutorials on the WinSCP website (for automated/unattended transfers but it gives me errors: Cannot created object, or cannot find library (from the dll file that I have associated with the COM)

The error I get when I run the following code is:

line 13, Char: 2
Could not created object named "WinSCP.SessionOptions"
Code: 80040154
Source: Wscipt.CreateObject

I should also probably mention that I get a similar error about line 21 or 22 about creating the Session object, when I remove the code on line 13 to see if it was the only issue

<job>                                                               
<reference object="WinSCP.Session"/>

<script language="VBScript">




Option Explicit

' Setup session options
Dim sessionOptions
Set sessionOptions = WScript.CreateObject("WinSCP.SessionOptions")
With sessionOptions
    .Protocol = Protocol_Sftp
    .HostName = "host"
    .UserName = "username"
    .Password = "password"
End With

Dim session
Set session = WScript.CreateObject("WinSCP.Session")

' Connect and Get
session.Open sessionOptions

 session.GetFiles("/Fromn/*.*", "C:\testFilesFrom").Check()



' Disconnect, clean up
session.Dispose

</script>
</job>

Has anyone had any experience scripting this kind of job where the server is not logged on and the script can run an SFTP session? Is there somethign I am doing wrong or is this not possible?

ScottC
  • 452
  • 8
  • 25

1 Answers1

1

WinSCP was made for interactive use. Use PSCP for non-interactive jobs. And I'd strongly recommend using public key authentication instead of password authentication.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • unfortunately the authentication method isn't up to me but I will mention it to the FTP site admin, and I will try PSCP in the mean time – ScottC Nov 12 '12 at 19:47
  • so I have found many sites showing how to script PSCP by sending keys but I already was able to do that, I can't find any site showing non interactive scripting for PSCP...any sites you could point me to? – ScottC Nov 14 '12 at 19:59
  • `pscp -?` reveals an option `-pw passwd login with specified password`. – Ansgar Wiechers Nov 15 '12 at 01:08
  • right but these commands involve running it as if you had a console open which fails when I run it under task scheduler on windows server, it runs (as it should) when I click it manually from windows, but when the system has no users logged in and it should run (and task scheduler confirms that the task ran) but no log file is generated like it is when I run it by clicking it Any suggestions on running it unattended/non interactive/not logged in to the server/scheduled – ScottC Nov 15 '12 at 18:15
  • `pscp` can be scripted just fine. Please explain in more detail what exactly you're doing, what result you expect, and what result you actually get. – Ansgar Wiechers Nov 15 '12 at 20:14
  • I think it just worked, but what I did was put the commands for PSCP into a batch file and had VBScript run the batch file instead – ScottC Nov 15 '12 at 20:59