Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Net::FTP Help

by Anonymous Monk
on Aug 26, 2002 at 13:46 UTC ( [id://192859]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

All, I am trying to use the NET::FTP package to remotely connect to a unix machine. However, we have disabled remotely
logging in as ROOT. Therefore I have to login as a regular user and then SU to root.

The problem comes when I try to issue the command "su - root". How do I deal with the fact that I am prompted to
enter the password ? I can't enter the password using the "cmd" operation as I just receive a timeout.

Any help, much appeciated.

Replies are listed 'Best First'.
Re: Net::FTP Help
by RMGir (Prior) on Aug 26, 2002 at 14:12 UTC
    Hmmm, it sounds like you're misusing Net::FTP.

    If nothing else, by trying to log in as root via Net::FTP, you'd be broadcasting your root password in the clear across the network (or, if you're working remotely without a VPN, the internet).

    Check out Net::SCP, which is a more secure protocol for moving files around.
    --
    Mike

Re: Net::FTP Help
by cybear (Monk) on Aug 26, 2002 at 16:07 UTC
    I don't know of anyway to "SU" when using FTP. The FTP server on my Solaris
    server will not recognize the "su" command, no matter how I issue it.
    There is no way of sending the password to "su" as a command line parameter
    anyway. So... I don't think that you will get this to work.

    Here is a work-around. Use Net::Telnet to start a telnet session, su to root
    in that telnet session, then as root:

    1) the untested version:
    start an ftp session and set it to display on your terminal.
    example: ftp someserver.com -display your.ip.add.ress:0.0
    this may not work and you need to have a way of displaying the incoming
    data. i.e. you need to be on a unix machine running Xwindows,
    or have an emulator running.

    2) the tested verions:
    start a shell session, /usr/bin/sh for example, and display it to your
    terminal. /usr/bin/sh -display your.ip.add.ress:0.0
    correction=>after the shell shows up on your system, use it to ftp to your machine
    same rules as above, you will need to be on a unix machine running Xwindows
    or have an emulator running.

    Good Luck

    - cybear

      Absolutely no idea what you are talking about there:
      ftp someserver.com -display your.ip.add.ress:0.0
      You seem to be confusing ftp and sh with X apps. FTP (unless you have some goofy replacement ftp client like mftp or something renamed as ftp in your path) is not graphical and the –display flag will just error out on you. Your solution will not work and really does not answer this posters problem.

      On to the problem, the original poster is confused between telnet and FTP. FTP is File Transfer Protocol; there is no su command for FTP. You have two (or maybe even more) issues here.

      First, Net::FTP will allow you to connect to a remote FTP server and login, upload and download files list directories and so on. If this is not what you are looking for then you need a different module.
      Second After reading your question I think I can pull out what your problem is, you are trying to use Net::FTP to connect to a ftp server, you are trying to login to the ftp server as root and since /etc/ftpusers (or wherever the file that accomplishes the same thing is on your ftp server) has a “root” entry you can't log in as root. Why do you need to log in as root? FTP auth is all plain text and anyone on your network could snoop your root password – root login via FTP is a _BAD_ idea. I would take a step back and think about what you are trying to accomplish. Do you really need root access to push or pull the files from that server? If the answer is yes I would consider using the SCP mods to do so. SCP uses encrypted logins and file transfers. If the answer is no I would set up the push or pop locations to be usable by a non system user and do the transfers that way. If you feel like your really _MUST_ login as root directly with FTP then (depending on the ftpd your system uses – some are hard coded not to allow root logins ever) you may edit the file /etc/ftpaccess on the ftp server and remove “root” from the file. That will allow you to login as root with FTP. If you choose the last approach there is something wrong with you. =)

      -Waswas
        Sorry for the confusion... let me be more precise.

        I have effectively beaten the same limitation that is sited in the original post.
        You need to be on a unix/linux workstation running Xwindows, or you need to have
        an Xwindows emulator, such as eXceed, running on your Windows/Mac workstation. Then...

        Write your Perl script to use Net::Telnet. Log in to the remote machine. Then "su" to root, /usr/bin/su - root
        as root have your script start a shell session /usr/bin/sh -display what.every.your.ip
        and pass it the "display" parameter. This WILL send the output from the shell to the IP address
        that you specify.

        Once your shell window opens up on your workstation, you can have your script start ftp. You will be
        starting FTP as root. The main diffrence will be that you must put instead of get.

        disclamer: this will not work "server-to-server". This will only work, as discribed, if you are
        trying to connect from a workstation, running unix/linux, or a workstation running an Xwindows
        emulator... but it absolutely does work.

        - cybear

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://192859]
Approved by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found