Wednesday, November 19, 2008

Script to Connect to FTP by passing username/password thru txt file

AccountInfo.txt
-------------------
user username password
prompt
binary
mget *.*
quit

ConnectFTP.cmd
-------------------
C:
cd C:\Temp
ftp -n -s:C:\Temp\AccountInfo.txt FTPHost
exit

Tuesday, November 18, 2008

Shell Script to connect to SFTP

Then connect to your machine and type

$ sftp username@HostName
Connecting to Host...
username@Host's password:
sftp>

if you already created a key pair to not promt for password then you would directly connect to SFTP with out prompting for the password

$ sftp username@HostName
Connecting to Host...
sftp>

Shell Script to connect to SFTP and upload/download files

#vi SFTPupload.sh will open a vi editor to edit/create the shell script
vi SFTPupload.sh
sftp username@hostname EOF
#sftp -b /dev/stdin username@hostname EOF
mput *.*
quit

then enter :wq it will save and comeout of the vi editor

Connect to SFTP with out prompting for Password (passwordless)

To script connecting to SFTP with out prompting for a password ,you would need to generate key pairs to do authentication. To do passwordless SFTP follwo the steps to create a key on your machine:

$ /bin/ssh-keygen -t dsa

Keep the default values for the all the prompts just by clikcing on enter.

$ /bin/ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_dsa):
Created directory '/home/username/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_dsa.
Your public key has been saved in /home/username/.ssh/id_dsa.pub.
This will generate the key pairs (id_dsa & id_dsa.pub)


The file called id_dsa.pub is the public_key and id_dsa must be private.
Copy the publick key to authorized_keys in your remote machine

You would find the file in .ssh directory in the remote machine.

If authorized_keys file not already there in remote machine , Place it in the .ssh directory on the remote machine and call it authorized_keys. You may have more than public key in the authorized_keys file.one for each remote machine.