1826975 Members
3163 Online
109705 Solutions
New Discussion

Re: script for FTP

 
SOLVED
Go to solution
Goran Bulut_1
Advisor

script for FTP

Hi all,

We are running hp 10.20
Is it possible to write script (file) for the FTP?
User
Pass
And to copy all files from current directory to another ftp server.

where should be saved this script (location)
Best regard to all

Goran
9 REPLIES 9
Michael Tully
Honored Contributor

Re: script for FTP

Hi,

This subject comes up frequently:

You can do a search using 'ftp script' from the search bar <-- or you could look at this posting:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x83e45f260cafd4118fef0090279cd0f9,00.html

There is also some interesting information that can be found in the 'netrc' man pages.

Cheers
~Michael~

Anyone for a Mutiny ?
S.K. Chan
Honored Contributor
Olav Baadsvik
Esteemed Contributor

Re: script for FTP


Hi,

Here is a small script that does what
you have requested:#!/bin/ksh
#
# In this script tohost is the name of the machine you want to
# copy files to.
# user is the users name on tohost
# passwd is the users password on tohost
#
# Replace mput ftp* with whatever is suitable for your use
# or add more ftp-commands
#
# The BIG security-issue with this method often is that the
# user/password is visible in a file!!!
# I have tried to reduce this risk here by having the user
# pass user/password as arguments to the script:
#
# usage:
# ftp_aut tohost user password
#
#
#
tohost=$1
USERNAME=$2
PASSWORD=$3
(
echo "
open $tohost
user $USERNAME $PASSWORD
mput ftp*
close
"
) | ftp -i -n

echo "exit script"

Regards
Olav

Justo Exposito
Esteemed Contributor

Re: script for FTP

Hi Goran,

Perhaps this information is important for you,
please read the man pages for .netrc.

Regards,

Justo.
Help is a Beatiful word
Gabriele FACCHINI
Frequent Advisor

Re: script for FTP

this is a simple example:

#! /usr/bin/sh

ip_address=10.10.10.10
user=user
password=password

ftp -n $ip_address <<-EOF
user $user $password
cd /tmp
lcd /tmp
bin
mput *
bye
EOF

Gabriele Facchini
Gabriele Facchini
Goran Bulut_1
Advisor

Re: script for FTP

Hi all,

This shoud be my first script on Hp
and sorry
Can I use any editor to create it under #! /usr/bin/sh

The name "out"
What shoul be extension of the file.
sorry to all.

best regard

Goran
S.K. Chan
Honored Contributor
Solution

Re: script for FTP

You would use "vi" editor to create the script file. For example .. (assuming you're root) ..

# vi myscript

..that will bring you to vi mode. And in "vi" enter your script .. (I'm using the previous posting example given..)

#! /usr/bin/sh

ip_address=10.10.10.10
user=user
password=password

ftp -n $ip_address <<-EOF
user $user $password
.....

When you're done save the file <:> and enter wq! and that will create file myscript. No extension is needed. Just make sure the permission of the file is executable.

# chmod 500 myscript

Then just run it ..

# ./myscript
Goran Bulut_1
Advisor

Re: script for FTP

thanks all for reply

Goran
Arockia Jegan
Trusted Contributor

Re: script for FTP

Here's a very simple script,

#!/bin/ksh
ftp -n << FTP
user
bin
prompt
mput *
FTP

********

You should use prompt before using mput if you want to upload/download mulitple files. If you don't use, it will ask for your confirmation before uploading/downloading the files.