Mercurial > gftp.yaz
comparison docs/parse-netrc.pl @ 1:8b1883341c6f
Initial revision
author | masneyb |
---|---|
date | Mon, 05 Aug 2002 19:46:57 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:674ed97069fd | 1:8b1883341c6f |
---|---|
1 #!/usr/bin/perl -w | |
2 | |
3 # Brian Masney <masneyb@gftp.org> | |
4 | |
5 my ($host, $user, $pass, $account, $descr, %bmhash); | |
6 use strict; | |
7 | |
8 open NRC, "<.netrc" or die "Can't open .netrc: $!\n"; | |
9 open BM, "+>>.gftp/bookmarks" or die "Can't open .gftp/bookmarks: $!\nTry running gFTP once to create a default bookmarks file\n"; | |
10 seek (BM, 0, 0); | |
11 while (<BM>) | |
12 { | |
13 ($descr) = /\[(.*?)\]/; | |
14 next if !defined ($descr); | |
15 $bmhash{$descr} = 1; | |
16 } | |
17 | |
18 seek (BM, 0, 2); | |
19 | |
20 while (<NRC>) | |
21 { | |
22 if (/machine /) | |
23 { | |
24 print_bookmark (); | |
25 ($host) = /machine (.*?)\s+/; | |
26 } | |
27 | |
28 if (/login /) | |
29 { | |
30 ($user) = /login (.*?)\s+/; | |
31 } | |
32 | |
33 if (/password /) | |
34 { | |
35 ($pass) = /password (.*?)\s+/; | |
36 } | |
37 | |
38 if (/account /) | |
39 { | |
40 ($account) = /account (.*?)\s+/; | |
41 } | |
42 } | |
43 | |
44 print_bookmark (); | |
45 | |
46 close NRC; | |
47 close BM; | |
48 | |
49 print "The contents of your .netrc file should now be stored in .gftp/bookmarks\n"; | |
50 | |
51 | |
52 sub print_bookmark | |
53 { | |
54 my $i; | |
55 | |
56 return if !defined ($host); | |
57 | |
58 if (!defined ($bmhash{$host})) | |
59 { $descr = $host; } | |
60 else | |
61 { | |
62 for ($i=0; ; $i++) | |
63 { | |
64 $descr = "$host ($i)"; | |
65 last if !defined ($bmhash{$descr}); | |
66 } | |
67 } | |
68 | |
69 | |
70 print BM "[$descr]\n"; | |
71 print BM "hostname=$host\n"; | |
72 print BM "port=21\n"; | |
73 print BM "protocol=FTP\n"; | |
74 print BM "remote directory=\n"; | |
75 print BM "local directory=\n"; | |
76 if (!defined ($user)) | |
77 { $user = "anonymous"; } | |
78 print BM "username=$user\n"; | |
79 if ($user eq "anonymous" || !defined ($pass)) | |
80 { $pass = "\@EMAIL\@"; } | |
81 print BM "password=$pass\n"; | |
82 if (!defined ($account)) | |
83 { $account = ""; } | |
84 print BM "account=$account\n\n"; | |
85 | |
86 print "Added $descr = $user\@$host\n"; | |
87 | |
88 undef ($host); | |
89 undef ($user); | |
90 undef ($pass); | |
91 undef ($account); | |
92 } | |
93 |