[英]shell sftp download remote file
How to download the lastest file via sftp in command line? 如何在命令行中通过sftp下载最新文件?
This connects to the server and lists the current directory.. But how can I find the last file sorted by filename and download it? 这将连接到服务器并列出当前目录。但是,如何找到按文件名排序的最后一个文件并下载呢?
sshpass -p $pass sftp root@$host << EOF
cd /var/www/bak/db
dir
quit
EOF
#!/bin/sh
pass="pwd"
host="ftps://host:22"
mkdir /ftp
cd /ftp
curlftpfs $host /ftp -o user=root:$pass
ls
Error connecting to ftp: gnutls_handshake() failed: An unexpected TLS packet was received.
Maybe that 也许那个
Get latest file and save to batchfile
file: 获取最新文件并保存到batchfile
文件:
ssh user@server "find /path/to/dir -type f -printf 'get %p\n' | sort -n | tail -1" > batchfile
And get file: 并获取文件:
sftp -b batchfile user@server:/
I checked and it works! 我检查了,它可以工作了!
It may be more convenient to use CurlFtpFS
to mount sftp
folder. 使用CurlFtpFS
挂载sftp
文件夹可能更方便。 Tutorial on "using curlftpfs to mount a FTP folder" explains details. 有关“使用curlftpfs挂载FTP文件夹”的教程详细说明。
And then use standard commands to achieve what you want to do. 然后使用标准命令来实现您想要的操作。
Or for sshfs
follow tutorial on how to Mount a SFTP Folder (SSH + FTP) . 或者对于sshfs
遵循有关如何挂载SFTP文件夹(SSH + FTP)的教程。
Not sure which sftp
do you mean. 不确定您是指哪个sftp
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.