首页 > 其他分享 >sftp命令详解

sftp命令详解

时间:2023-07-02 13:01:01浏览次数:41  
标签:remote key -- sftp 命令 详解 file path append


Looks like sftp doesn't  distinguish Binary files and ASCII files at all. That means it doesnt support the commands like 'bin' or 'ascii' that ftp supports.

sftp> help
 Available commands:
 bye                                Quit sftp
 cd path                            Change remote directory to 'path'
 chgrp grp path                     Change group of file 'path' to 'grp'
 chmod mode path                    Change permissions of file 'path' to 'mode'
 chown 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 [-P] remote-path [local-path]  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 oldpath newpath                 Symlink remote file
 lpwd                               Print local working directory
 ls [-1aflnrSt] [path]              Display remote directory listing
 lumask umask                       Set local umask to 'umask'
 mkdir path                         Create remote directory
 progress                           Toggle display of progress meter
 put [-P] local-path [remote-path]  Upload file
 pwd                                Display remote working directory
 quit                               Quit sftp
 rename oldpath newpath             Rename remote 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 
===================================================
Usage: sftp [options]...
               [profile|[user@]host[#port]]Access remote files using the Secure Shell protocol.
Options:
   -b buffer_size_bytes  Define maximum buffer size for one
                         request (default: 32768 bytes).
   -B batch_file         Use batch file.
   -D, --debug=LEVEL     Set debug level string to LEVEL.
   -N max_requests       Define maximum number of requests sent in
                         parallel (default: 10).
   -P port               Connect to this SSH port on the remote
                         machine (default: 22).
   -v, --verbose         Use verbose mode (equal to `-D 2').
   --keep-alive=VALUE    Send no-operational packet to the server, 
                         each specified amount of time.
   --tcp-connect-timeout=VALUE
                         Overwrite default timeout value that is
                         used when connecting to a server.
   -i file               Use private keys defined in identification
                         file to authenticate with public key method.
   --identity=ID         Use private key 'id' as user identification.
                         The 'id' can be either key id, key hash or 
                         a key file name.
   --identity-key-id=ID  Use key id as a user identification.
   --identity-key-hash=ID
                         Use key hash as a user identification.
   -K, --identity-key-file=FILE
                         Use key file as a user identification.
   --allowed-authentications=METHODS
   --aa=METHODS
                         Allow only selected methods in user
                         authentication. The 'methods' is a comma 
                         separated list of authentication methods.
                         Giving value 'help' lists available methods.
   --kip                 Same as '--aa=keyboard-interactive,password'.
   -c, --ciphers=CIPHERS Allow only selected ciphers to be used.
                         Giving value 'help' lists available ciphers.
   --macs=MACS           Allow only selected MACs to be used.
                         Giving value 'help' lists available MACs.
   --kexs=KEXS           Allow only selected KEX methods to be used.
                         Value 'help' lists available KEX methods.
   --hostkey-algorithms=HOSTKEYALGORITHMS
                         Allow only selected hostkey algorithms to be
                         used. Value 'help' lists available hostkey
                         algorithms
   -C                    Disables compression.
   +C                    Enables zlib compression.
   --compressions=METHODS
                         Allow selected compression methods.
                         Giving value 'help' lists available methods.
   --exclusive           Opens always a new connection, does not share
                         connection.
   --fips                Performs checksums using the FIPS
                         cryptographic library.
   --password=           Set user password. Giving the PASSWORD
         PASSWORD|       directly as the argument is not secure!
         file://FILE|    Give either a path to FILE containing the
         extprog://PROG  password, or a path to external program
                         that will output the password.
   --plugin-path=PATH    Set plugin path to PATH. This is only
                         used in FIPS mode.
   -V, --version         Display program version and exit.
   -q, --quiet           Suppress the printing of error, warning and
                         informational messages.
   -h, --help            Display this help and exit. 
=========
StringBuffer cmd = new StringBuffer(sftpSSH);
   String space = " ";
   cmd.append(space).append("PUT");
   cmd.append(space).append(ftpInfo.getFtpUser());
   cmd.append(space).append(ftpInfo.getFtpDestination());
   cmd.append(space).append(ftpInfo.getFtpPort());
   cmd.append(space).append(localDir);
   cmd.append(space).append(ftpInfo.getFtpFolder());
   cmd.append(space).append(fileName);
   
   String remoteFileName = ftpInfo.getFtpFileName();
   if(ftpInfo.getFtpFileDateFormat()!=null && ftpInfo.getFtpFileType()!=null)
   {
    Date d = new Date();
    String s  = DateFormatUtils.format(d,ftpInfo.getFtpFileDateFormat());
    remoteFileName=remoteFileName+s;
    remoteFileName=remoteFileName+'.'+ftpInfo.getFtpFileType();
   }
   cmd.append(space).append(remoteFileName);  logger.info("call sftp shell command:" + cmd.toString());
   Process proc = Runtime.getRuntime().exec(cmd.toString());
    BufferedReader in = new BufferedReader (new InputStreamReader(proc.getInputStream()));
         BufferedReader inE = new BufferedReader (new InputStreamReader(proc.getErrorStream()));
         StringBuffer errMsg = new StringBuffer();
         String s = null;
         errMsg.append("\nSFTP script Stand Output:\n");
         while ((s = in.readLine()) != null){
             s = s.trim();
             errMsg.append(s+"\n");
         }
         errMsg.append("\nSFTP script Err Output:\n");
         while((s = inE.readLine()) != null){
             if(s.trim().length() > 0){
                 errMsg.append(s+"\n");                    
             }
         }
         return errMsg.toString();=====================================
if [ $CMD = "PUT" ]; then
  logInput $1 $2 $3 $4 $5 $6 $7 $8
   checkLocalDir $5
   checkFileExist "$5$FILESEP$7" $CMD
   
   if [ "$5$FILESEP$7" != "$5$FILESEP$8" ]; then
    cp "$5$FILESEP$7" "$5$FILESEP$8"
   fi
   
         BATCHFTPFILE=/tmp/sftpUtilBatch
         echo lcd $5 > $BATCHFTPFILE
         echo cd $6 >> $BATCHFTPFILE
         echo put $8 >> $BATCHFTPFILE  returnC=`/usr/local/bin/sftp -B $BATCHFTPFILE $2@$3#$4`
   
   if [ $? = 1 ]; then
    echo $returnC >>$LOGFILE
    echo $returnC
          exit 1
   fi
   
   if [ "$5$FILESEP$7" != "$5$FILESEP$8" ]; then
    rm "$5$FILESEP$8"
   fi
   
   echo $returnC >>$LOGFILE
   echo $returnC
         exit 0
 fi ==================

sftp -i ~/.ssh2/identification

.ssh2/下包含identification 文件和xxx.key.pub

identification的内容是key xxx.key.pub

xxx.key.pub的内容是密钥

标签:remote,key,--,sftp,命令,详解,file,path,append
From: https://blog.51cto.com/u_16174476/6604519

相关文章

  • linux su命令卡顿,linux su特别慢问题排查
    问题:发现同机房两台同网络域的主机,一台su用户正常,一台每次都需要等5s左右。进展:杂事儿太多没深入排查,后续又发现了几台有同样问题的主机。非常影响效率。开始入手排查分析:1、之前遇到过类似问题,ssh登陆慢。所以首先观察两台主机sshd_config配置文件,发现登录慢的主机多了一个配......
  • Linux命令(38)之mount
    Linux命令之mount1.mount介绍linux命令mount是用来挂载linux系统外的文件2.mount用法mount[参数] devicedirmount常用参数参数说明-a将/etc/fstab中定义的所有档案系统挂上-t指定档案系统的类型,通常不必指定,mount会自动选择正确的类型-V显示版本信息-v显示挂载信息3.实例3.1.......
  • 【WALT】WALT入口 update_task_ravg() 代码详解
    目录【WALT】WALT入口update_task_ravg()代码详解代码展示代码逻辑⑴ 判断是否进入WALT算法⑵ 获取WALT算法中上一个窗口的开始时间⑶如果任务刚初始化结束⑷ 更新任务及CPU的cycles⑸ 更新任务及CPU的demand及pred_demand⑹ 更新CPU的busytime⑺ 更新任务的p......
  • 【WALT】update_window_start() 代码详解
    目录【WALT】update_window_start()代码详解代码展示代码逻辑【WALT】update_window_start()代码详解代码版本:Linux4.9android-msm-crosshatch-4.9-android12代码展示staticu64update_window_start(structrq*rq,u64wallclock,intevent){ s64delta; intnr_window......
  • Docker CLI docker container inspect 常用命令
    Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的Linux或Windows操作系统的机器上,也可以实现虚拟化。Docker是内核虚拟化,不使用Hypervisor是不完全虚拟化,依赖内核的特性实现资源隔离。本文主要介绍DockerCLI中d......
  • Linux文件系统、常用文件操作命令及用户权限
    1、熟悉Linux的文件系统结构Linux的文件系统结构其实是一个树形的分层组织结构,如下图:Linux系统目录结构及目录路径:1.1、文件系统层次结构标准Linux是开源的操作系统,各个Linux发行机构都可以按照自己的需求对Linux系统的文件系统进行相应的裁剪,所以各个Linux发行版本的目录结构......
  • OpenWrt+R2S 主路由、旁路由配置详解
    1、R2S用作主路由R2S作为主路由的好处,所有流量都经过软路由,客户端不需要额外配置坏处:所有流量都经过软路由1.1网络拓扑1.2R2S的WAN口配置家庭一般都是光猫拨号,光猫的网口直接连上R2S的WAN口,R2S一般保持默认配置就好,即配置DHCP客户端自动获取IP地址就好了。比如你是校园......
  • 详解Java中跳跃表的原理和实现
    原文链接及讲解:详解Java中跳跃表的原理和实现java跳表实现importjava.util.Collections;importjava.util.List;importjava.util.stream.Collectors;importjava.util.stream.Stream;/***java跳表实现**@authorlyn*@date2023/6/3018:50*/publicclass......
  • 什么是 CSR、SSR、SSG、ISR - 渲染模式详解
    本文以React、Vue为例,介绍下主流的渲染模式以及在主流框架中如何实现上述的渲染模式。前置知识介绍看渲染模式之前我们先看下几个主流框架所提供的相关能力,了解的可跳到下个章节。挂载组件到DOM节点这是主流框架最基本的能力,就是将组件渲染到指定的DOM节点上。在React......
  • dpkg-reconfigure命令找不到问题解决
    作者: adminhttps://cloudbool.com/archive/dpkg-reconfigure-command-not-found.html今天在SSH远程连接到服务器时,遇到了dpkg-reconfigure命令找不到的问题,觉得很是奇怪,花了点时间研究下,这里做个记录,以备后用。前情提要我远程的服务器系统是自行使用DebiannetinstISO镜......