Question

How to download the lastest file via sftp in command line?

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

update

#!/bin/sh

pass="pwd"
host="ftps://host:22"

mkdir /ftp
cd /ftp
curlftpfs $host /ftp -o user=root:$pass
ls

error

Error connecting to ftp: gnutls_handshake() failed: An unexpected TLS packet was received.
Was it helpful?

Solution

Maybe that

Get latest file and save to batchfile file:

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!

OTHER TIPS

It may be more convenient to use CurlFtpFS to mount sftp folder. Tutorial on "using curlftpfs to mount a FTP folder" explains details.

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).

Not sure which sftp do you mean.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top