Configuring SFTP File Transfer in MobaXterm: Automatically Copy Files to/from the /tmp Folder
In this article, we will discuss how to configure an SFTP session in MobaXterm and set up automatic file transfers to and from the /tmp folder on a remote device.
Prerequisites
To follow along with this article, you will need:
- MobaXterm installed on your local machine.
- Access to a remote device with SFTP enabled.
Configuring an SFTP Session
To configure an SFTP session in MobaXterm, follow these steps:
- Open MobaXterm and click on the "Session" button in the top left corner.
- In the "Session settings" window, select "SFTP" from the dropdown menu.
- Enter the hostname or IP address of the remote device in the "Remote host" field.
- Enter your username and password in the respective fields.
- Click on the "Advanced SSH settings" button.
- In the "Advanced SSH settings" window, check the box next to "Use private key" and browse to the location of your private key file.
- Click "OK" to close the "Advanced SSH settings" window.
- Click "OK" to close the "Session settings" window and establish the SFTP session.
Setting Up Automatic File Transfers
To set up automatic file transfers to and from the /tmp folder on the remote device, follow these steps:
- In the MobaXterm terminal window, navigate to the local directory containing the files you want to transfer.
- Enter the following command to create a symbolic link to the
/tmpfolder on the remote device:
ln -s sftp://username@remote_host:/tmp/ ~/tmp
Replace "username" with your username on the remote device and "remote_host" with the hostname or IP address of the remote device.
- Verify that the symbolic link has been created by listing the contents of your home directory:
ls -la ~
You should see a new directory called "tmp" that is linked to the /tmp folder on the remote device.
- To automatically copy files to the
/tmpfolder on the remote device, simply move them into the "tmp" directory on your local machine. - To automatically copy files from the
/tmpfolder on the remote device, create a script that uses thescpcommand to transfer the files. For example, the following script will transfer all files with a ".txt" extension from the/tmpfolder on the remote device to your local "tmp" directory:
#!/bin/bash
scp username@remote_host:/tmp/*.txt ~/tmp
Replace "username" with your username on the remote device and "remote_host" with the hostname or IP address of the remote device.
- Save the script as a .sh file and make it executable using the following command:
chmod +x script.sh
- Schedule the script to run at regular intervals using a tool like cron.
Conclusion
In this article, we have discussed how to configure an SFTP session in MobaXterm and set up automatic file transfers to and from the /tmp folder on a remote device. By creating a symbolic link to the /tmp folder and using the scp command in a script, you can easily transfer files to and from the remote device without manually initiating the transfers.
References
- MobaXterm documentation: https://mobaxterm.mobatek.net/documentation.html
- SFTP documentation: https://www.ssh.com/ssh/sftp/
- Symbolic links documentation: https://www.gnu.org/software/coreutils/manual/html_node/ln-invocation.html
scpcommand documentation: https://www.man7.org/linux/man-pages/man1/scp.1.html- Cron documentation: https://www.man7.org/linux/man-pages/man8/cron.8.html