view docs/parse-netrc.pl @ 56:a12bcbc2fce4

2002-11-11 Brian Masney <masneyb@gftp.org> * src/gtk/dnd.c - fixes to DnD code * src/gtk/gftp-gtk.[ch] - added main_thread_id variable * src/gtk/misc-gtk.c (ftp_log) - don't check the user_data to see if we're in a child thread, instead compare the value of pthread_self() with main_thread_id * src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/menu-items.c src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/transfer.c - don't set user_data to 0x1 if we're in a child thread * lib/gftp.h src/gtk/misc-gtk.c src/text/gftp-text.c - make r_getservbyname() available even if HAVE_GERADDRINFO is defined * lib/misc.c (make_ssh_exec_args) - if port is zero, lookup the default port for the ssh service * lib/protocols.c (gftp_connect_server) - if the port is zero, store the default port for that protocol there * src/gtk/transfer.c - added function update_window_transfer_bytes(). Be able to update the directory download progress in window1 now * lib/config_file.c lib/misc.c lib/protocols.c lib/ssh.c lib/sshv2.c src/text/gftp-text.c - use g_strdup() instead of g_strconcat() where needed
author masneyb
date Mon, 11 Nov 2002 23:16:12 +0000
parents 8b1883341c6f
children
line wrap: on
line source

#!/usr/bin/perl -w

# Brian Masney <masneyb@gftp.org>

my ($host, $user, $pass, $account, $descr, %bmhash);
use strict;

open NRC, "<.netrc" or die "Can't open .netrc: $!\n";
open BM, "+>>.gftp/bookmarks" or die "Can't open .gftp/bookmarks: $!\nTry running gFTP once to create a default bookmarks file\n";
seek (BM, 0, 0);
while (<BM>)
  {
    ($descr) = /\[(.*?)\]/;
    next if !defined ($descr);
    $bmhash{$descr} = 1;
  }

seek (BM, 0, 2);

while (<NRC>)
  {
    if (/machine /)
      {
        print_bookmark ();
        ($host) = /machine (.*?)\s+/;
      }

    if (/login /)
      {
        ($user) = /login (.*?)\s+/;
      }

    if (/password /)
      {
        ($pass) = /password (.*?)\s+/;
      }

    if (/account /)
      {
        ($account) = /account (.*?)\s+/;
      }
  }

print_bookmark ();

close NRC;
close BM;

print "The contents of your .netrc file should now be stored in .gftp/bookmarks\n";


sub print_bookmark
{
  my $i;

  return if !defined ($host);
 
  if (!defined ($bmhash{$host}))
    { $descr = $host; }
  else
    {
      for ($i=0; ; $i++)
        {
          $descr = "$host ($i)";
          last if !defined ($bmhash{$descr});
        }
    }
  

  print BM "[$descr]\n";
  print BM "hostname=$host\n";
  print BM "port=21\n";
  print BM "protocol=FTP\n";
  print BM "remote directory=\n";
  print BM "local directory=\n";
  if (!defined ($user))
    { $user = "anonymous"; }
  print BM "username=$user\n";
  if ($user eq "anonymous" || !defined ($pass))
    { $pass = "\@EMAIL\@"; }
  print BM "password=$pass\n";
  if (!defined ($account))
    { $account = ""; }
  print BM "account=$account\n\n";

  print "Added $descr = $user\@$host\n";

  undef ($host);
  undef ($user);
  undef ($pass);
  undef ($account);
}