脚本 SFTP 无人值守下载 [英] Scripting SFTP unattended download

查看:72
本文介绍了脚本 SFTP 无人值守下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过名为 WinSCP 的软件连接到 SFTP 服务器,该软件是一个安全的 FTP 客户端,我可以通过发送密钥并在伪无人值守模式下执行它来编写脚本以使其工作,但服务器必须有用户登录在发送密钥时,我需要 WinSCP 登录并传输文件,就像控制台未启动的服务一样.

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.

我已经尝试按照教程 WinSCP 网站(用于自动/无人值守传输,但它给了我错误:无法创建object,或 cannot find library(来自我与 COM 关联的 dll 文件)

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

我可能还应该提到,当我删除第 13 行的代码以查看它是否是唯一的问题时,我在第 21 或 22 行关于创建 Session 对象时遇到了类似的错误

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>

有没有人在服务器未登录且脚本可以运行 SFTP 会话的情况下编写此类作业的脚本?是我做错了什么还是不可能?

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?

推荐答案

WinSCP 是为交互式使用而设计的.将 PSCP 用于非交互式作业.我强烈建议使用公钥身份验证而不是密码身份验证.

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.

这篇关于脚本 SFTP 无人值守下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆