34

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?

jrara
  • 2,069
  • 8
  • 23
  • 20
  • Related: http://unix.stackexchange.com/questions/91544/move-a-remote-file-at-an-ftp-prompt – slm Sep 30 '13 at 11:58

2 Answers2

51

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.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Dario Seidl
  • 2,346
  • 1
  • 20
  • 21
2

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>

References

slm
  • 363,520
  • 117
  • 767
  • 871