sftp批处理文件无法执行

时间:2019-07-30 06:07:04

标签: ftp sftp

我有一个Windows批处理文件,可以从服务器A(Windows)连接到 服务器B(UNIX)通过sftp获取文件。脚本如下:

sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg@hostnameB
lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG
exit

当我运行脚本时,它将在运行第一行即sftpg3 -oStrictHostKeyChecking = no ...

后停止运行。

D:\APPBASE\EAPSG\GEMSSG>sftpg3 -oStrictHostKeyChecking=no -oIdentityFile=EAPIINSTADM_hostnameA ftpeapsg@hostnameB
Warning: ignoring unsupported option -o
Warning: ignoring unsupported option -o
Remote system type is POSIX.
sftp>

它没有执行以下行:

lcd D:\APPBASE\EAPSG\GEMSSG
get GENUOBGW1 /sftp/ftphrssg/HRSSG/EAPSG

如果我一次手动运行该命令,那么它将起作用。

您知道为什么脚本无法完全运行吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

这是因为sftpg3是类似于sftp的客户端,它提示与服务器等待输入的交互式会话。因此,脚本中的第一行只是打开会话,然后等待该命令(即打开的提示符)退出。您需要将输入重定向到该提示的会话中(在Unix中,如使用<<一样),我不知道该如何在Windows中完成。但是如果编写该脚本的目的是从服务器复制文件,则可以使用scpg3