Tool for uploading/downloading files to/from SAP system using SCP command
Why I write this tool
When I am installing an SAP system from scratch. I use the SCP command to upload the downloaded files from SAP download centre to my SAP server. This tool is useful and great except that every time I need to type in the server IP address and destination folder, also my login credential. So I decided to write a small batch program to store that information. Later on, I think why not make it a general tool which can be used by others. Thus, I write this blog to share the work.
The SAPCP command
Usually, you will use the scp command as below:
scp -i <ssh_key_file> <files_to_upload> <user>@<host>:<destination>
By using my tool, you can use the following command:
sapcp -h <host> -u <user> -d <destination> -k <ssh_key_file> <files_to_upload>
All parameters can be ignored by a default value or with environment variables, of course, except the <files_to_upload>. The parameters are self-explanatory, below is a copy of the usage information of my tool.
Usage: sapcp [-h <host>] [-u <user>] [-d <destination>] [-k <ssh_key_file>] [-dl] <files...> -h Destination host name or ip address. -u Logon user to host. Default value: root -d Destination directory. Default value: /root/sap_download -k Key file for scp connection. Default location is '~\.ssh\id_rsa'. -dl Download file from remote server. <file> Filename to be uploaded or downloaded. You can use wild char to match multiple files. e.g. *.zip, k*.sar Use of environment variables: You can specify several environment variables to ignore some of the options. SAPCP_HOST => <host> SAPCP_USER => <user> SAPCP_DESTINATION => <destination> You can always override the environment variable value by specifying the related options, e.g. if SAPCP_DESTINATION exists, but you use sapcp -d /some_other_dir The file will be upload to 'some_other_dir' instead of the directory defined in SAPCP_DESTINATION.
If you are interested to use my tool, you can get it from GitHub.
Installation steps, you may ignore any step if you did it already.
- Download the ‘sapcp.cmd’ file to any folder.
- Add that folder into your path environment variable.
- Configure the ssh client to generate the ssh_key file.
- Logon to the remote server, make the destination directory.
- Configure your local environment variables for SAPCP_HOST, SAPCP_USER, SAPCP_DESTINATION.
If you set up everything ready, the only parameter is the file that you want to upload. E.g.
You don’t have to specify the credentials and destination folder every time you run the scp command.
You can also upload all files from a directory:
The scp command support both direction transfer, so you can download a file. You need to specify the -DL parameter, the default folder is the current folder.
sapcp -dl file_to_be_download.zip
Help me to improve
I wish my tool can make your life easier. Also, any comment or suggestion is welcome. I can improve the tool to be more flexible and more convenient.