SFTP使用bash脚本发送文件 [英] SFTP to send file with bash script

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

问题描述

我正在使用密钥身份验证,因此密码不是问题.我有一个名称已知的文件,我只想通过sftp将其发送到另一台计算机.

I'm using key authentication, so password is not an issue. I have a file whose name I know and I simply want to send it to another machine over sftp.

我尝试搜索,但是在任何地方都找不到这个(看似简单)的问题.也许我的Google-fu今天简直让我失望.

I tried searching but couldn't find this (seemingly simple) question anywhere. Perhaps my Google-fu is simply failing me today.

简而言之:我在本地计算机上,想将文件(test.txt)发送到远程计算机.已提供授权密钥.基本上,我想自动化这三个步骤:

In short: I'm on my local machine, want to send a file (test.txt) to a remote machine. Authorized keys are already provided. Basically I want to automate these three steps:

sftp root@remote:/root/dropoff
put test.txt
quit

是否有一个简单的bash命令可用于自动执行此操作?我看到的唯一选项是使用bash脚本执行put/quit,并使用-b选项运行它.有没有比这更清洁的东西了? (我对使用任何其他应用程序/工具不感兴趣.)

Is there a simple bash command I can use to automate this? The only option I've seen is using a bash script to perform the put/quit and using the -b option to run it. Is there anything cleaner than that? (I'm not interested in using any other applications/tools.)

谢谢!

推荐答案

您说您对其他工具不感兴趣,但是scp是无人值守文件传输的更好选择.这是一个scp示例:

You said that you are not interested in other tools, but scp is a much better choice for unattended file transfers. Here is an scp example:

scp test.txt root@remote:/root/dropoff

这篇关于SFTP使用bash脚本发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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