How can I move a file in sftp server on a different directory? I connect to this server using sftp and then try to move a file using

mv myfile.csv /my/dir/myfile.csv

but this generates an error. How to to do this?


2 Answers 2


There is no mv command in the interactive mode of sftp. Use rename instead.

To learn which commands are available, check the man page man sftp or type help within sftp.

  • 14
    sftp's rename works just like mv in the shell!
    – Devy
    Dec 12, 2014 at 0:38
  • 6
    @Devy except for wildcards, and omitting the filename if moving into a dir!
    – pstanton
    Jul 16, 2015 at 1:12

The client lftp can be used for both FTP and SFTP. It has a mv command you can use to perform a move on the remote server. There's a good tutorial on using it here, titled: Unix: Flexibly moving files with lftp.

If you look through the lftp usage you'll notice a mv command.

$ lftp
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 [<level>|off] [-o <file>]
    du [options] <dirs>                  exit [<code>|bg]                     get [OPTS] <rfile> [-o <lfile>]      glob [OPTS] <cmd> <args>             help [<cmd>]
    history -w file|-r file|-c|-l [cnt]  jobs [-v]                            kill all|<job_no>                    lcd <ldir>
    lftp [OPTS] <site>                   ln [-s] <file1> <file2>              ls [<args>]                          mget [OPTS] <files>
    mirror [OPTS] [remote [local]]       mkdir [-p] <dirs>                    module name [args]                   more <files>
    mput [OPTS] <files>                  mrm <files>                          mv <file1> <file2>                   [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 [-O <dir>] <file|URL>...     user <user|URL> [<pass>]             wait [<jobno>]                       zcat <files>                         zmore <files>


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .