Operating System - HP-UX
1752282 Members
4849 Online
108786 Solutions
New Discussion юеВ

How to use host commands in an ftp session

 
SOLVED
Go to solution
Suman_7
Frequent Advisor

How to use host commands in an ftp session

1. Is it possible to use UNIX host commands in an ftp session?

like ...

$ftp> grep *.*

2. what is the command to connect from one UNIX host to another UNIX box ..

like telnet

I tried the same its not working. Please advice.

Thanks
Suman
12 REPLIES 12
Scott Palmer_1
Trusted Contributor

Re: How to use host commands in an ftp session

Suman,

In answer to question 2 the answer
is telnet
wait for user name: type
wait for password and type

if you want to log in automatically, you have to look at rlogin, or some variation of that.

I am also not completely clear, what your first question is, so if you can elaborate, i may be able to answer

Regards,
Scott
Scott Palmer_1
Trusted Contributor

Re: How to use host commands in an ftp session

as a sub answer to part 2, if you put a 2nd argument in the telnet after the boxname (or ipaddress) it sees it as a port number
for example telnet 127.0.0.1 5555 would telnet to port 5555 on your local machine (HP Data Protector daemon port).

Scott
Steven E. Protter
Exalted Contributor

Re: How to use host commands in an ftp session

For security reasons, ftp is not permitted to run host commands like telnet. A lot of effort has been made to make sure this is so.

Here is a script that can do this:

########################
#Start Ftp and get file#
########################
ftp -nv ${SERVER} << FTPEOF > /tmp/temp_log.$$
user ${USERNAME} ${PASSWORD}
#Get file
get $1
bye
FTPEOF


You can insert commands before the ftp line or avter the FTPEOF statement, but not in the middle.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Suman_7
Frequent Advisor

Re: How to use host commands in an ftp session

Thanks for your reply.

How do I use rlogin

I am trying
$rlogin < remote hostname> <-l username>

but it comes back asking for password. I need to write a script to connect to remote box without being prompted for username or password.


I have to do a complex logic to check the availability of specific file name pattern on the remote box. If the file is not available then my script has to come back again to this box after 30 minutes and check again.

Please advice.

Thanks
Suman
Marvin Strong
Honored Contributor

Re: How to use host commands in an ftp session

to use rlogin, you would need to setup .rhosts for the user running the script on the target machine. In said users home directory.

So my .rhosts would look be something like this.
/home/mstrong/.rhosts
permissions 644

The contents of the file look as follows:
athena mstrong

where athena would be the remote host, and mstrong would be the username on that host.


Suman_7
Frequent Advisor

Re: How to use host commands in an ftp session

Mavin,

thanks for your reply. But my question is about the password. How can I avoid being prompted for password. Can i save this password somewhere? Please advice?

I tried using
$rlogin -l

Ss there any way I can specify the password in the same command line?

I have to write a script that will connect to the remote box without being prompted for username and password.

Thank You,
Suman



Thank You,
Suman Kumar
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to use host commands in an ftp session

Actually, what you want to do is very easy using Perl Net::FTP module.

Create a .netrc file on the host containing an entry like this in the FTP clients home directory, it should have mode 600 and be owned by the user (dumbo, in this case):

machine bozo login dumbo passwd elephant

No password will then be need by rhe "r" commands, FTP, or Perl using these commands. Now use the attached script to attempt to get the file "ears" from directory "/trunk" on host "bozo".

ftpget.pl -h bozo -l dumbo -d /trunk ears
STAT=${?}

if [[ ${STAT} -eq 0 ]]
then
echo "All ok"
else
echo "Failed; status = ${STAT}; try again later"
fi

That's all you have to do; if "ears" isn't found, the result is 5.

Because Net::FTP also has the ls and dir FTP commands, you can make this script as powerful as you like.
If it ain't broke, I can fix that.
Nicolas Dumeige
Esteemed Contributor

Re: How to use host commands in an ftp session

the .rhost is used to declare host as recognize, i.e. whithout the need of authentification process.

Put the remote host first, then the username.
# cat >.rhosts
localhost bob
^D

Cheers

Nicolas
All different, all Unix
Suman_7
Frequent Advisor

Re: How to use host commands in an ftp session


A. Clay Stephenson Thanks for your reply. I am trying to log from machine A to machine B. I using the user "ftp_user" to login to the remomte machine "B" . ftp_user has an account on B but he doesn't have an account on A. Since "ftp_user" doesn't have an account on A I can't make it the owner of .netrc file. I hope I understand what you are tyring to say..

regards
Suman