Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Editing remote *nix files from Windows?

by flamey (Scribe)
on Dec 15, 2009 at 17:12 UTC ( #812905=perlquestion: print w/ replies, xml ) Need Help??
flamey has asked for the wisdom of the Perl Monks concerning the following question:

What options do I have in reading/writing remote files on located on Linux machine from Windows system?

I have IP, Login and Password for the remote Linux system, and I can manually access it (SSH) and do the editing. But I need to update some files automatically.

I guess one option could be telneting in, reading using 'cat' command, and overwriting via 'echo' and redirect (?? - i'm not Linux user). But is there an option to do it more gracefully?

Edit: I should've mentioned that I can't do anything in Linux side - this is for testing, not administration. That's why it has to be done from outside.

Comment on Editing remote *nix files from Windows?
Re: Editing remote *nix files from Windows?
by vlsimpson (Beadle) on Dec 15, 2009 at 17:21 UTC

    The linux box should have text editors installed; vim, emac, etc.

    You could edit the files locally also, and ship 'em over by sftp. Check out Putty (Google it). It's a real nice telnet client that handles ssh, sftp, scopy for windows.

      that's what I'm using for manual editing - Putty + mc

      how does that help me to do it with perl?

      the FTPing suggestion is good though

        Oops, completely misunderstood the question.
Re: Editing remote *nix files from Windows?
by ikegami (Pope) on Dec 15, 2009 at 17:28 UTC
      Thanks, I'll give this a try!
Re: Editing remote *nix files from Windows?
by Fletch (Chancellor) on Dec 15, 2009 at 18:52 UTC

    Another possibility to consider (if you can make changes or coerce the sysadmin to make changes) would be to use Samba and mount the files from the Linux box as a remote drive on the Windows side and treat them as any other locally accessible file.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Editing remote *nix files from Windows?
by elTriberium (Friar) on Dec 15, 2009 at 19:41 UTC

    You can also write a Perl script that will run on the Linux system. Then you can use Expect.pm to login to that client and execute the Perl script on the Linux system.

    Or you login with Expect and just run the command line tools that you mentioned, such as cat, echo, touch, ...

      Note that under Windows Expect only works when used inside the Cygwin port of Perl.
Re: Editing remote *nix files from Windows?
by eye (Chaplain) on Dec 15, 2009 at 19:41 UTC
    But I need to update some files automatically.

    Is this something that could be done with a Perl script on the linux host that is initiated by cron on a regular schedule?

Re: Editing remote *nix files from Windows?
by snoopy (Deacon) on Dec 15, 2009 at 19:52 UTC
    Another possibility is to map a network drive via ssh on Windows.

    The drive can be mapped via Putty.

    There are several other approaches, including Dokan (a FUSE emulation for Windows).

    Update: Thanks afoken, good point!

    • The Putty solution requires that a local Samba service is running on the remote machine. This is then tunnelled via ssh back to the Windows machine.
    • The Dokan and other FUSE family solutions are a different animal. These run directly over ssh and should be able to be used on just about any *nix machine that's serving ssh, without prior setup.

      Nice trick, but it requires Samba or the like on the remote unix machine installed and running -- something that rarely happens on a machine connected directly to the internet, and for a good reason.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      Hmmm, things I forgot to wrote last time:

      • PuTTY comes with some very useful helper programs:
        PAgent
        A key agent, so you don't need to enter your password a billion times a day. Enter the key pass phrase once Windows loads PAgent, and PuTTY will be able to use the key without any prompts.
        PSCP
        A simple command line scp client, sufficient for small batch jobs or perl scripts. Can use PuTTYs saved sessions and the keys from PAgent.
        PSFTP
        A command line sftp (not FTP!) client, sufficient for occasional file transfers. Like PSCP, it can use saved sessions and the keys from PAgent.
        PLink
        A command line ssh client, "PuTTY without the terminal emulator". Usually called from batch jobs or scripts to invoke remote programs or to create an SSH tunnel.
        PuTTYGen
        A ssh key generator, uses its own format and can export / import OpenSSH and ssh.com formats
      • There is a companion program called WinSCP, it can import PuTTYs sessions and can use the keys from PAgent. Basically, it is a graphical SCP and SFTP client, but can also talk plain old FTP. Recent versions also have a very limited command line window (without full terminal emulation) and a useable text editor for remote files. It can behave either like a Windows Explorer window or like a graphical clone of the Norton Commander.
      • From lots of experience, I would recommend to create a private key, export it to the remote system, and DISABLE password logins via SSH on the remote system. A nice side effect is that you don't have to type passwords any more, but the real benefit is that no one will be able to login via SSH to the remote machine, even if he correctly guesses login and password.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-10-25 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls