How to Bulk Rename/Move Files in SFTP Without mv Command: A Complete Guide for Solaris Systems


2 views

When working with SFTP (SSH File Transfer Protocol) on Solaris systems, you might encounter a frustrating limitation: the inability to move multiple files simultaneously using wildcards. Unlike local shell operations where mv *.txt destination/ works perfectly, SFTP's rename command only handles single file operations.

The error message Couldn't rename file "current_path/*" to "current_path/DestinationFolder/": Bad message occurs because SFTP protocol version 2 (which you're using) doesn't support wildcard operations in the rename command. This is a protocol limitation, not just a client implementation issue.

Since you don't have SSH access and can't use shell commands directly, here are your best options:

Option 1: SFTP Batch File Approach

Create a local text file containing all rename commands:

rename current_path/file1.txt current_path/DestinationFolder/file1.txt
rename current_path/file2.log current_path/DestinationFolder/file2.log
rename current_path/data.csv current_path/DestinationFolder/data.csv

Then execute it in your SFTP session:

sftp> !cat commands.txt | sftp -b - user@host

Option 2: Using SFTP Shell Looping

If your client supports limited shell operations, try:

sftp> !for f in $(ls current_path/*); do echo "rename $f current_path/DestinationFolder/${f##*/}" >> move_commands.sftp; done
sftp> !sftp -b move_commands.sftp user@host

Option 3: Temporary Script Generation

For large numbers of files, generate commands dynamically:

sftp> ls current_path/
sftp> !sftp user@host << EOF
$(for f in $(ls current_path/ | grep -v DestinationFolder); do
  echo "rename current_path/$f current_path/DestinationFolder/$f"
done)
EOF

Remember that Solaris handles some commands differently than Linux:

  • ls output format might vary
  • Wildcard expansion behaves differently
  • Path names are case-sensitive

Consider using GUI SFTP clients that support bulk operations:

  • WinSCP (Windows) has powerful batch processing
  • FileZilla supports queue-based transfers
  • Cyberduck (macOS) allows multiple file selection

Since you mentioned not having full SSH access, be aware that:

  • SFTP is encrypted and secure for file transfers
  • Batch operations don't expose more attack surface
  • Solaris' default SFTP configuration is typically restrictive

When working with SFTP protocol version 2 on Solaris systems, you'll notice the absence of a native mv command for bulk file operations. The standard SFTP client only provides rename for single-file operations, which creates challenges when needing to move multiple files between directories.

From the available commands list shown in the help output, we can see these relevant operations:

rename oldpath newpath   # Renames/moves single file
ls [path]                # Lists remote files
rm path                  # Deletes files
mkdir path               # Creates directories

The most efficient method is to create an SFTP batch script containing multiple rename commands. Here's how to implement it:

  1. First, generate the list of files to move:
  2. sftp> ls current_path/* > filelist.txt
    
  3. Process this list into rename commands:
  4. awk '{print "rename current_path/"$1" current_path/DestinationFolder/"$1}' filelist.txt > move_commands.sftp
    
  5. Execute the batch file:
  6. sftp -b move_commands.sftp user@host
    

If batch files aren't an option, you can use this interactive approach:

sftp> cd current_path
sftp> ls
file1.txt file2.log data.csv  # Example output
sftp> rename file1.txt DestinationFolder/file1.txt
sftp> rename file2.log DestinationFolder/file2.log
sftp> rename data.csv DestinationFolder/data.csv
  • The destination directory must exist before renaming files
  • Wildcards (*) don't work with SFTP's rename command
  • Solaris SFTP implementations may have additional restrictions
  • For large numbers of files, consider compressing them first

Here's a complete example of what your move_commands.sftp file might contain:

cd current_path
rename report_Jan.pdf DestinationFolder/report_Jan.pdf
rename data_2023.csv DestinationFolder/data_2023.csv
rename config.ini DestinationFolder/config.ini
quit