How to move or rename a file on the SFTP server that has just been uploaded or downloaded?

If you need to move a file on the SFTP server after a successful upload or download operation, you should use a post-transfer trigger.

A post-transfer trigger is executed after a successful file transfer between the remote server and the local computer and allows you to execute any sequence of shell commands or a shell script. As parameters, you can use built-in FTPGetter variables such as the %remote_file% variable, which represents the full path of the transferred file on the SFTP server, date-related variables, and others.

Important note! To execute shell commands on the SFTP server, your account must have shell access rights. It is very easy to check whether you have these rights — you should be able to execute commands on the SFTP server in the terminal. If your account on the SFTP server does not have such rights, contact the SFTP server administrator to request this permission!

Example #1: Move the transferred file to another folder on the SFTP server.

To perform this operation, add the following command to the shell script text field.


mv %remote_file% /%remote_file_name%


SFTP shell command to move file on SFTP server

How it works. After a successful file transfer, FTPGetter executes the mv shell command with two parameters. The first parameter is the %remote_file% variable, which contains the full path of the recently transferred file (on the SFTP server). The second parameter is the new full file name on the SFTP server.

Important note! We do not recommend moving, renaming, or deleting transferred files because the next time FTPGetter starts executing the scheduled task, it will obviously not find the file on the SFTP server (since we just renamed/moved/deleted it!) and will transfer it again! We recommend first copying the transferred file to another folder and then performing various operations on it there.

Below are examples of different shell commands for moving files:

Example #2: Moving a file while adding the current date to the file name.


mv %remote_file% /%remote_file_name_only%-%c_yyyy%-%c_mm%-%c_dd%.%remote_file_name_ext%

SFTP shell command to move file on SFTP server

Example #3: Moving a file with a new .done extension


mv %remote_file% /%remote_file_name_only%.done

SFTP shell command to move file on SFTP server

Example #4: Renaming a file while adding the current date to the file name.


mv %remote_file% %remote_file_path%/%remote_file_name_only%-%c_yyyy%-%c_mm%-%c_dd%.%remote_file_name_ext%

SFTP shell command to move file on SFTP server

Next, we will look at how to copy or unzip a recently uploaded file on the SFTP server.

Need to move a file on the local computer after transfer?

Back on top