I am using the following syntax to connect to an FTP server and paste the file.
Based on the value in the variable $Folder, i want to connect to different folders on the same server. The credential is different to access different folders. How to get the user name and password from a config file for each folder?
I dont want to Hard code the credentials in my shell script.
Folder= FolderA or FolderB.
ftp -pin $Test_host <<++
quote USER $USER
quote PASS $PASSW
cd $Folder
put $FILE.txt
bye
++
Currently i have hardcoded the FTP user name and password in the script.
I did not use any config file.
Config file should have all the FTP user ids and password to access different folders on the same server.
Is it possible to use .netrc file? Can we have multiple user id and password for the same server in the file and select the user name and password based on the value in a variable?
If the server is at a known, fixed IP address, you can assign it two names in /etc/hosts like this. Then either name will connect you to the same server.
192.168.1.21 serverA serverB
Then make a ~/.netrc file with both usernames and passwords. (Of course make sure ~/.netrc has file mode 0600.)
Then just access whichever server you want. The username and password will be handled automatically.
You may even be able to put macdef init in ~/.netrc for each server to change directories automatically. Though I'm not sure that works for every implementation.