Jump to content
 English      
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
     Forums advanced search
HP.com Home
IT Resource Center Forums > HP-UX > languages and scripting

perl script - chown within/after ftp?

» 

IT Resource Center

» Login
» Register
» My profile
» Search knowledge base
» Forums
» Patch database
» Download drivers, software and firmware
» Warranty check
» Support Case Manager
» Software Update Manager
» Training and Education
» More maintenance and support options
» Online help
» Site map

Member icons
 
 HP moderator  HP moderator
 Expert in this area  Expert in this area
Member status
ITRC Pro ITRC Pro
250 points
ITRC Graduate ITRC Graduate
500 points
ITRC Wizard ITRC Wizard
1000 points
ITRC Royalty ITRC Royalty
2500 points
ITRC Pharaoh ITRC Pharaoh
7500 points
Olympian Olympian
20000 points
1-Star Olympian 1-Star Olympian
40000 points
2-Star Olympian 2-Star Olympian
80000 points
»  How to earn points
»  Support forums FAQs
Question status
Magical answer Magical answer
Message with a response that solved the author's question
Favorites status
Add to my favorites Add to my favorites
Delete from my favorites Delete from my favorites
This thread has been closed Thread closed
 

Content starts here
   Create a new message    Receive e-mail notification if a new reply is posted  Reply to this message
Author Subject: perl script - chown within/after ftp?      Add to my favorites
so.nimda
Nov 5, 2009 03:34:28 GMT   

Hi,

I have written a perl script to ftp a file from a Windows XP PC to a HP-UX server using the Net:FTP module.

The ftp part is working fine but I need to 'chown' the file once it is ftp-ed over in the UX directory.

How can it be done?

This is how the script looks like :

use Net::FTP;
$ftpobj = Net::FTP -> new ("myserver");
$ftpobj -> login("id","password");
$ftpobj -> cwd ("/home/temp");
$ftpobj -> ascii;
$ftpobj -> put (myfile);
$ftpobj -> quit;

I don't think its possible within the ftp command - "$ftpobj -> chown (id, group, filename)" doesn't work.

Do I have to separately (within the script) do a 'telnet' and then 'chown'?

Thanks !
Note: If you are the author of this question and wish to assign points to any of the answers, please login first.For more information on assigning points ,click here


Sort Answers By: Date or Points
Steven Schweda This member has accumulated 7500 or more points
Nov 5, 2009 04:52:10 GMT  8 pts

> [...] a HP-UX server [...]

Not a very complete description of this
system.

> [...] I need to 'chown' [...]

Why?  Who owns the files now, and whom would
you like to own them?

The FTP server on my HP-UX 11.31 system seems
to offer a "SITE CHMOD" command, but "chown"
typically requires some unusual privilege, so
I wouldn't expect an FTP server to offer it.

> [...] do a 'telnet' and then 'chown'?

And as whom were you planning to log in to do
that job?  (You want to put _which_ password
into this script?)  Even rsh/remsh can offer
better security than a password embedded in
a script.  Ssh could be safer than rsh/remsh
for executing a remote command, but if you
give some user the power to do chown, what
else have you made possible?

If you care not at all about security, then
tasks like this get easier.
so.nimda
Nov 5, 2009 07:59:46 GMT    N/A: Question Author

Hi Steven,

Thanks for the reply.

It's actually a UX 11v23 test system that I'm playing with so security is not a concern for now.

There's a series of steps that I'm trying to automate whereby I :

1) ftp a file from my PC to the UX server using root
2) login as root and chown the file to a specific user

The easiest way will be to ftp using that user but unfortunately, no one can remember the password and the file is used by an application running under that user ID - so the need for the chown.

The chown is pretty straight forward, e.g. chown user:ugroup filename

Nothing fancy and no need for any unusual privileges.

Hope this clarifies.

Thanks
izad This member has accumulated 500 or more points
Nov 5, 2009 08:09:09 GMT  9 pts

Hi,

Not clear why you want to run chown, however if you want to do that anyway, you can use the Net::Telnet module within your perl script so that it does the 'chown' after the file is succesfully transferred.

use Net::Telnet;
$telnet = new Net::Telnet ( Timeout=>10, Errmode=>'die' Prompt => '/\$ $/i'); $telnet->open('host or IP'); $telnet->login('username', 'passwd'); print $telnet->cmd('chown usr:grp /path/to/file');

hth

regards,
James R. Ferguson This member has accumulated 80000 or more points
Nov 5, 2009 13:36:40 GMT  9 pts

Hi:

> The easiest way will be to ftp using that user but unfortunately, no one can remember the password and the file is used by an application running under that user ID - so the need for the chown.

Why don't you (as 'root') change the password of the target user to something you know and then do your FTP as that user?

You could also use SFTP (I suggest Perl's 'Net::SFTP::Foreign' module) having setup public keys in lieu of hardcoding cleartext passwords.

Regards!

...JRF...
Steven Schweda This member has accumulated 7500 or more points
Nov 5, 2009 14:53:28 GMT  8 pts

> Why don't you (as 'root') change the
> password [...]?

Especially considering:

> It's actually a UX 11v23 test system that
> I'm playing with so security is not a
> concern for now.

Sometimes the easy way really is the easy
way.
so.nimda
Nov 6, 2009 00:04:23 GMT    N/A: Question Author

Thanks for all your replies.

Using root to change the password of the target user is indeed a good
solution but my fear is that once changed, things may not work (either due
to configuration, hardcoding, etc ) - that's why I'm hesitant to go that way.

Thanks again for all the help and suggestions.
Viktor Balogh This member has accumulated 500 or more points
Nov 6, 2009 11:39:23 GMT    Unassigned

if the perl script runs on the HP-UX side, you could make it simply by

system("chown user:ugroup filename");
with the root user

or

system("sudo chown user:ugroup filename");
and by grating passwordless sudo to the user executing the perl script
Dennis Handly Expert in this area This member has accumulated 40000 or more points
Nov 6, 2009 11:48:24 GMT    Unassigned

>but my fear is that once changed, things may not work (either due to configuration, hardcoding, etc) - that's why I'm hesitant to go that way.

Simply save the old passwd entry and if problems, you can always put it back.
 
Create a new message    Receive e-mail notification if a new reply is posted   Reply to this message
 
 
Printable version
Privacy statement Using this site means you accept its terms
© 2009 Hewlett-Packard Development Company, L.P.