Reputation: 1
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
#!/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.
Upvotes: 0
Views: 4626
Reputation: 3088
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!
Upvotes: 2
Reputation: 2221
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.
Upvotes: 1