lftp
lftp Cheatsheet
About
lftp is a command line FTP file transfer client.
Documentation
man lftp LFTP Pocket Reference
Install
$ apt-get install lftp
$ brew install lftp
C:\> chocolatey install lftp
Configure
$HOME/.lftprc
Tab completion for bookmarks
See lftp-completion
Supported protocols
- FTP
- SFTP
- FTPS
- FTPES
- FISH
- HFTP
- HTTP
- HTTPS
Connect to server
$ lftp [-u <username>,<password>] <URL>
Create a bookmark
> bookmark add <name>
Connect to bookmarked server
$ lftp <name>
Quit
> quit
Or
Control+D
Change local directory
> lcd <local directory>
View local directory
> lpwd
Change remote directory
> cd
View remote directory
> ls
Update file listing
cache flush
Download single file
> get <file>
Download single file faster via parallel segments
> pget <file>
Upload file
> put <file>
Download directory
> mirror <remote directory>
Upload directory
> mirror -R <local path> <remote path>
Create directory
> mkdir
Move file or directory
> mv <current filename> <new filename>
Delete file or directory
> rm [-r] [-f] <file or directory>
> rmdir <directory>
User lftp in script
cat << EOF | tee "${lftp_command}"
open -p $ftp_port $ftp_host
user $ftp_user '$ftp_pass'
## Some ftp servers hide dot-files by default (e.g. .htaccess), and show them only when LIST command is used with -a option.
set ftp:list-options -a
## if true, try to negotiate SSL connection with ftp server for non-anonymous access. Default is true. This and other ssl settings are only available if lftp was compiled with an ssl/tls library.
set ftp:ssl-allow no
mkdir -pf $remote_dir
put \
-c \
-O $remote_dir \
$local_file
quit
EOF
lftp -f "${lftp_command}"
keep alive
# 启动背景进程发送PWD命令保持连接活跃
(
while true; do
# 使用ncftp或其他FTP工具发送NOOP命令
# 示例中使用lftp,因为它支持发送任意命令
echo "PWD" | lftp -u ${ftp_user},${ftp_pass} -p ${ftp_port} ${ftp_host}
sleep 300 # 每5分钟发送一次
done
) &
参考:
- https://mrod.space/2019/10/04/lftp-examples
- https://github.com/mcandre/cheatsheets/blob/master/lftp.md
文档信息
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
- 发表日期: 2024-05-06T09:34:39Z