来自终端的单线 sftp [英] Single line sftp from terminal

查看:27
本文介绍了来自终端的单线 sftp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一天中,我可能会多次运行测试,我需要查看远程服务器上的日志文件.我已经习惯使用我的终端sftp 进入远程服务器并将所需的日志文件下拉到本地机器上的/tmp.

我今天正在使用 man sftp 查看选项,试图找出一种基本上在一行中运行以下命令的方法,这样我就不必键入命令,按回车键,输入命令按回车键等

(我现在在做什么)

sftp myuser@myserver--mypassword 提示液晶显示器/tmp获取/dir/dir/dir/dir/file退出

我在查看 man sftp 时发现了一个我以前没有使用过的对 scp 的引用.我觉得这可能是我正在寻找的,但我没有看到一种方法来指定我希望安全复制的文件去哪里.

有人可以为我提供一种从远程服务器获取 /dir/file 并将其下载到 /tmp/file_plus-my-description 的方法吗?>

我希望能够运行类似于常规 UNIX 副本的 sftp 或 scp 命令,例如:

scp myuser@myserver/dir/file/tmp/file_plus-my-description

我在 Mac OS X 10.8 中使用内置的 Terminal.谢谢.

解决方案

2017 年 9 月更新 - tl;dr

从远程 ftp 服务器下载单个文件到您的机器:

sftp {user}@{host}:{remoteFileName} {localFileName}

上传单个文件从您的机器到远程 ftp 服务器:

sftp {user}@{host}:{remote_dir} <<<$'put {local_file_path}'

<小时>

原答案:

好吧,所以我觉得有点傻.但我想通了.我几乎把它放在了顶部:

sftp user@host remoteFile localFile

终端中显示的唯一文档是:

sftp [user@]host[:file ...]sftp [用户@]主机[:目录[/]]

但是,我遇到了这个站点,它显示了以下内容简介:

sftp [-vC1] [-b 批处理文件] [-o ssh_option ] [-s 子系统 |sftp_server ] [-B buffer_size ] [-F ssh_config ] [-P sftp_server 路径] [-R num_requests ] [-S 程序] 主机sftp [[user@]host[:file [file]]]sftp [[user@]host[:dir[/]]]

所以简单的答案是您只需在用户和主机之后执行 : ,然后是远程文件和本地文件名.难以置信的简单!

单行,sftp复制远程文件:

sftp username@hostname:remoteFileName localFileNamesftp kyle@kylesserver:/tmp/myLogFile.log/tmp/fileNameToUseLocally.log

2016 年 2 月更新

如果有人正在寻找与此相反的命令,并在一行 sftp 命令中将文件从本地计算机推送到远程服务器,下面的用户@Thariama 发布了解决方案来实现这一目标.向他们提示额外的代码.

sftp {user}@{host}:{remote_dir} <<<$'put {local_file_path}'

Several times throughout the day, I may be running a test where I need to look through a log file on a remote server. I've gotten used to using my terminal to sftp into the remote server and pull the desired log file down to /tmp on my local machine.

I was looking through the options today using man sftp in an attempt to figure out a way to run the following commands basically in a single line so that I don't have to type a command, press enter, type a command press enter, etc.

(what I do now)

sftp myuser@myserver
--mypassword at prompt
lcd /tmp
get /dir/dir/dir/dir/file
quit

I found while looking through man sftp a reference to scp which I haven't used before. I feel it may be what I'm looking for, but I didn't see a way to specify where I wanted the securely copied file to go.

Could someone provide me with a way to get /dir/file from a remote server and have it download to /tmp/file_plus-my-description?

I was hoping to be able to run an sftp or scp command similar to a regularUNIX copy like:

scp myuser@myserver /dir/file /tmp/file_plus-my-description

I'm using the built in Terminal in Mac OS X 10.8. Thanks.

解决方案

Update Sep 2017 - tl;dr

Download a single file from a remote ftp server to your machine:

sftp {user}@{host}:{remoteFileName} {localFileName}

Upload a single file from your machine to a remote ftp server:

sftp {user}@{host}:{remote_dir} <<< $'put {local_file_path}'


Original answer:

Ok, so I feel a little dumb. But I figured it out. I almost had it at the top with:

sftp user@host remoteFile localFile

The only documentation shown in the terminal is this:

sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]

However, I came across this site which shows the following under the synopsis:

sftp [-vC1 ] [-b batchfile ] [-o ssh_option ] [-s subsystem | sftp_server ] [-B buffer_size ] [-F ssh_config ] [-P sftp_server path ] [-R num_requests ] [-S program ] host 
sftp [[user@]host[:file [file]]] 
sftp [[user@]host[:dir[/]]]

So the simple answer is you just do : after your user and host then the remote file and local filename. Incredibly simple!

Single line, sftp copy remote file:

sftp username@hostname:remoteFileName localFileName
sftp kyle@kylesserver:/tmp/myLogFile.log /tmp/fileNameToUseLocally.log

Update Feb 2016

In case anyone is looking for the command to do the reverse of this and push a file from your local computer to a remote server in one single line sftp command, user @Thariama below posted the solution to accomplish that. Hat tip to them for the extra code.

sftp {user}@{host}:{remote_dir} <<< $'put {local_file_path}'

这篇关于来自终端的单线 sftp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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