Rename (move) multiple files on remote server using sftp

I want to rename (move) multiple files on remote server. I tried the following command to move all TXT files from my_dir directory to /new_dir. But it does not work. Any help?

#!/bin/ksh
 
sftp -dev3 << ABC
     cd my_dir
     $(for i in TXT; do echo "ls *.$i" ;  rename $x /new_dir/$x; done)
ABC

--- Post updated at 08:32 PM ---

Correction : The remote server is dev3 and not -dev3.

Increase the logging level of sftp and read the errors.

What OS are you using? (this is important).

If, for example Linux:

Ref: sftp(1) [linux man page]

Note, you can also set the logging level in ssh_config

Then, please look at your log files and post back any sftp session and error messages.

This is how you debug problems. First start with the log files and error messages.

Moderator comments were removed during original forum migration.

Hi @Soham,

Did you ever get this problem solved?

We did not yet hear back from you.

1 Like