PuTTY / PSFTP文件传输自动化的批处理文件 [英] Batch file for PuTTY/PSFTP file transfer automation

查看:2714
本文介绍了PuTTY / PSFTP文件传输自动化的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件,用于通过SFTP将文件从本地PC移动到服务器。我在系统中安装了PuTTY,并且批处理文件代码如下。

  cd C:\Program Files(x86)\ PuTTY 
psftp
open< IP>
< user>
< PW>
cd / home / irisuser / iris / integration / dls_dlsblr_dlschnn_in_msg / in
lcd d:\
put log.sh
bye

上面的代码在我在命令提示符下键入时完美地工作。但是当我双击 .bat 文件并运行它,它不运行,并要求输入用户名和密码。我的目标是自动化整个事情,我需要运行它只需点击 .bat 文件。但是我不能实现它。任何想法或片段都会帮助我。

解决方案

您需要存储psftp脚本( open 到 bye )转换为单独的文件,并将其传递给 psftp c> -b switch:

  cdC:\Program Files(x86)\ PuTTY
psftp -b script.txt

其中脚本。 txt 假定为 C:\Program Files(x86)\PuTTY 。或者提供一个完整的路径(不要忘记将路径括在双引号中,特别是如果它包含空格,最好使用 cd 命令)。 / p>

参考:

https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter6.html#psftp-option-b






编辑:对于用户名+密码:由于您不能使用 psftp 批处理文件,出于同样的原因,您不能指定用户名和密码为 psftp 命令。这些是 open 命令的输入。虽然您可以使用 open 命令( open< user> @< IP> )指定用户名,不能以这种方式指定密码。这可以在 psftp 命令行上完成。那么在命令行中可能更干净:

  cdC:\Program Files(x86)\ PuTTY
psftp -b script.txt< user> @< IP> -pw< PW>

并移除 open < user> < PW> 行。 script.txt



参考:

https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter6.html#psftp-starting

https://the.earth .li /〜sgtatham / putty / 0.67 / htmldoc / Chapter3.html#using-cmdline-pw



你正在做什么atm是你运行 psftp ,不带任何参数或命令。一旦你退出(例如键入 bye ),你的批处理文件继续尝试运行 open ,什么Windows shell显然不明白。


I have a batch file for moving file from my local PC to server through SFTP. I have PuTTY installed in my system and the batch file code follows.

cd C:\Program Files (x86)\PuTTY
psftp
open <IP>
<user>
<PW>
cd /home/irisuser/iris/integration/dls_dlsblr_dlschnn_in_msg/in
lcd d:\
put log.sh
bye

The above code perfectly works when I type it in command prompt. But when I double click the .bat file and run it, it's not running and asking for username and password to be entered. My aim was to automate the whole thing and I need to run it by simply clicking the .bat file. But am not able to achieve it. Any ideas or snippets will help me.

解决方案

You need to store the psftp script (lines from open to bye) into a separate file and pass that to psftp using -b switch:

cd "C:\Program Files (x86)\PuTTY"
psftp -b script.txt

Where script.txt is assumed to be in C:\Program Files (x86)\PuTTY. Alternatively provide a full path (Do not forget to enclose the path to double-quotes, particularly if it contain spaces. You should better do this with your cd command too).

Reference:
https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter6.html#psftp-option-b


EDIT: For username+password: As you cannot use psftp commands in a batch file, for the same reason, you cannot specify the username and the password as psftp commands. These are inputs to the open command. While you can specify the username with the open command (open <user>@<IP>), you cannot specify the password this way. This can be done on a psftp command line only. Then it's probably cleaner to do all on the command-line:

cd "C:\Program Files (x86)\PuTTY"
psftp -b script.txt <user>@<IP> -pw <PW>

And remove the open, <user> and <PW> lines from your script.txt.

Reference:
https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter6.html#psftp-starting
https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter3.html#using-cmdline-pw

What you are doing atm is that you run psftp without any parameter or commands. Once you exit it (like by typing bye), your batch file continues trying to run open command (and others), what Windows shell obviously does not understand.

这篇关于PuTTY / PSFTP文件传输自动化的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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