当前位置: 首页 > 工具软件 > LFTP > 使用案例 >

FTP、SFTP、LFTP文件传输协议使用

狄元魁
2023-12-01

文件传输协议

ftp

ftp - 文件传输协议,现在有更安全的sftp,以及更强大的lftp;命令基本相同,真的需要使用ftp可以使用man ftp

以及help再查看即可。

sftp

Sftp - OpenSSH 安全文件传输

语法:

sftp [-46AaCfNpqrv] [-B buffer_size] [-b batchfile] [-c cipher] [-D sftp_server_path] [-F ssh_config] [-i identity_file] [-J destination] [-l limit] [-o ssh_option] [-P port] [-R num_requests] [-S program] [-s subsystem | sftp_server] destination

连接命令:

# 不指定用户默认当前用户
sftp ip
# 指定用户
sftp 用户名@IP
# 指定端口
sftp -P port 用户名@IP
# destination也可以是一个url sftp://[user@]host[:port][/path]
sftp sftp://ip:port/test

连接远端服务器(可使用ssh免密连接):

sftp ip

连接成功后,本地执行命令:

!cd /home/zsl0

等价于

lcd /home/zsl0

远端执行命令:

cd /home

向远端传输test文件:

put test

向远端传输files文件夹:

put -r files

操作命令:

Available commands:
bye                                Quit sftp
cd path                            Change remote directory to 'path'
chgrp [-h] grp path                Change group of file 'path' to 'grp'
chmod [-h] mode path               Change permissions of file 'path' to 'mode'
chown [-h] own path                Change owner of file 'path' to 'own'
df [-hi] [path]                    Display statistics for current directory or
                                   filesystem containing 'path'
exit                               Quit sftp
get [-afpR] remote [local]         Download file
help                               Display this help text
lcd path                           Change local directory to 'path'
lls [ls-options [path]]            Display local directory listing
lmkdir path                        Create local directory
ln [-s] oldpath newpath            Link remote file (-s for symlink)
lpwd                               Print local working directory
ls [-1afhlnrSt] [path]             Display remote directory listing
lumask umask                       Set local umask to 'umask'
mkdir path                         Create remote directory
progress                           Toggle display of progress meter
put [-afpR] local [remote]         Upload file
pwd                                Display remote working directory
quit                               Quit sftp
reget [-fpR] remote [local]        Resume download file
rename oldpath newpath             Rename remote file
reput [-fpR] local [remote]        Resume upload file
rm path                            Delete remote file
rmdir path                         Remove remote directory
symlink oldpath newpath            Symlink remote file
version                            Show SFTP version
!command                           Execute 'command' in local shell
!                                  Escape to local shell
?                                  Synonym for help

lftp

Left - 复杂的文件传输程序

连接命令:

# 指定账号密码连接
lftp sftp://用户名:密码@IP:端口
lftp -u 用户名,密码@ sftp://IP
lftp -u 用户名,密码@ ftp://IP

# lftp中建立连接
lftp

# 指定协议 端口 账号密码(可使用ssh免密连接) 
open sftp://ip -p port -u user:password
# 等价于
open sftp://ip -p port
login user password

一行命令拉去文件:

lftp -c ‘open sftp://ip:port -u user:password; cd /home/zsl0; get kubernetes.conf;’

拉去文件夹内文件:

lftp -c ‘open sftp://ip:port; cd /home/files; lcd /Users/zsl0/files; mirror --no-recursion -I *.txt;’

其它命令:

lftp :~> help
    !<shell-command>                     
    (commands)                           
    alias [<name> [<value>]]
    attach [PID]                         
    bookmark [SUBCMD]                    
    cache [SUBCMD]
    cat [-b] <files>                     
    cd <rdir>                            
    chmod [OPTS] mode file...
    close [-a]                           
    [re]cls [opts] [path/][pattern]      
    debug [OPTS] [<level>|off]
    du [options] <dirs>                  
    edit [OPTS] <file>                   
    exit [<code>|bg]
    get [OPTS] <rfile> [-o <lfile>]      
    glob [OPTS] <cmd> <args>             
    help [<cmd>]
    history -w file|-r file|-c|-l [cnt]  
    jobs [-v] [<job_no...>]              
    kill all|<job_no>
    lcd <ldir>                           
    lftp [OPTS] <site>                   
    ln [-s] <file1> <file2>
    ls [<args>]                          
    mget [OPTS] <files>                  
    mirror [OPTS] [remote [local]]
    mkdir [OPTS] <dirs>                  
    module name [args]                   
    more <files>
    mput [OPTS] <files>                  
    mrm <files>                          
    mv <file1> <file2>
    mmv [OPTS] <files> <target-dir>      
    [re]nlist [<args>]                   
    open [OPTS] <site>
    pget [OPTS] <rfile> [-o <lfile>]     
    put [OPTS] <lfile> [-o <rfile>]      
    pwd [-p]
    queue [OPTS] [<cmd>]                 
    quote <cmd>                          
    repeat [OPTS] [delay] [command]
    rm [-r] [-f] <files>                 
    rmdir [-f] <dirs>                    
    scache [<session_no>]
    set [OPT] [<var> [<val>]]            
    site <site_cmd>                      
    source <file>
    torrent [OPTS] <file|URL>...         
    user <user|URL> [<pass>]             
    wait [<jobno>]

如上查看命令怎么使用时,使用 help <command>

 类似资料: