1

Could someone show me how to rename all files extension inside folder in sftp?

Example, I have folder "Test" in sftp and inside this folder have few files, such as, test1.tmp, test2.tmp..... and I want to rename all files that have extension 'tmp' to .csv. so the result after rename should be like this. test1.csv, test2.csv ...... But in sftp not all bash command that can execute.

I tried like this already

find . -name "*.tmp" -exec rename 's/\.tmp$/.csv/' '{}' \;

but it say Invalid Command, seem command find no working in sftp.

vibol
  • 11
  • 3

1 Answers1

1

There is a rename SFTP command too. If you're using Windows and using WinSCP then you're lucky enough to use wildcards and simply run rename *.tmp *.csv.

c:\WinSCP>WinSCP.com
winscp> open sftp://bcs78@example.com:22/ -privatekey=bcs78.key.ppk
Searching for host...
Connecting to host...
Authenticating...
Using username "bcs78".
Authenticating with public key "bcs78@laptop".
Authenticated.
Starting the session...
Session started.
Active session: [1] bcs78@example.com
winscp> ls
-rw-rw-r--   1 bcs78    bcs78            2 Aug 30 12:23:34 2018 03.tmp
drwxr-xr-x  14 bcs78    bcs78         4096 Aug 30 12:21:49 2018 ..
-rw-rw-r--   1 bcs78    bcs78            2 Aug 30 12:23:11 2018 01.tmp
drwxrwxr-x   2 bcs78    bcs78         4096 Aug 30 12:23:34 2018 .
-rw-rw-r--   1 bcs78    bcs78            2 Aug 30 12:23:23 2018 02.tmp
winscp> rename *.tmp *.csv
03.tmp
01.tmp
02.tmp
winscp> ls
-rw-rw-r--   1 bcs78    bcs78            2 Aug 30 12:23:23 2018 02.csv
drwxr-xr-x  14 bcs78    bcs78         4096 Aug 30 12:21:49 2018 ..
-rw-rw-r--   1 bcs78    bcs78            2 Aug 30 12:23:34 2018 03.csv
drwxrwxr-x   2 bcs78    bcs78         4096 Aug 30 12:23:54 2018 .
-rw-rw-r--   1 bcs78    bcs78            2 Aug 30 12:23:11 2018 01.csv
winscp>

In Linux you likely need to script this since the Openssh or the Putty implementation does not support wildcards.

bcs78
  • 372
  • 4
  • 9
  • Your answer uses WinSCP. In WinSCP `rename` command indeed supports wildcards. But your link points to OpenSSH `sftp` `rename` command, which does not support wildcards in `rename` command. You should correct/clarify this. – Martin Prikryl Dec 17 '18 at 09:54