-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathresume-uploader
executable file
·118 lines (86 loc) · 2.3 KB
/
resume-uploader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/perl
# resume-uploader.pl [email protected] 2011/12/12 18:48:22
use warnings;
use strict;
$|=1;
use Data::Dumper;
use Net::FTP;
use File::HomeDir;
my $MyWebsite = "direct.hollenback.net";
my $ResumeDir = "/public_html/personal";
my $ftp;
my $LocalHome = File::HomeDir->my_home;
my $LocalResumeDir = "$LocalHome/Documents/resume";
#################################################
# ftp_upload - shamelessly cribbed from #
# http://aplawrence.com/Unixart/perlnetftp.html #
#################################################
sub ftp_upload {
my $file = shift;
print "checking file $file on ftp server - ";
my $ftpsize = $ftp->size($file);
if (! $ftpsize)
{
print "not found, skipped\n";
return 0;
}
my $ftpmodtime = $ftp->mdtm($file);
my $stamp = gmtime $ftpmodtime;
my $modtime = (stat ("$LocalResumeDir/$file"))[9];
if ($modtime > $ftpmodtime)
{
$ftp->put("$LocalResumeDir/$file",$file);
print "uploaded\n";
}
else
{
print "not newer, skipped\n";
}
}
########
# main #
########
if ($#ARGV < 0)
{
print "nothing to do!\n";
exit 0;
}
$ftp = Net::FTP->new($MyWebsite, Debug => 0)
or die "Cannot connect to $MyWebsite: $@";
# use .netrc to login
$ftp->login()
or die "Cannot login ", $ftp->message;
$ftp->cwd($ResumeDir)
or die "Cannot change working working directory: ", $ftp->message;
# now I'm in the right directory, see if I need to upload resume files.
foreach my $file (@ARGV)
{
if (! -r "$LocalResumeDir/$file")
{
print "skipping unreadable file $LocalResumeDir/$file\n";
} else
{
ftp_upload($file);
}
}
$ftp->quit;
exit 0;
__END__
=head1 NAME
resume-uploader.pl
=head1 SYNOPSIS
resume-uploader.pl <file> [<file> ...]
=head1 DESCRIPTION
Uploads my resume files to my website via ftp. Assumes username/password already configured in .netrc.
Meant to be called from resume makefile.
Only uploads files if they already exist on server.
=head1 AUTHOR
Philip J. Hollenback, E<lt>[email protected]<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 by Philip J. Hollenback
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.2 or,
at your option, any later version of Perl 5 you may have available.
=head1 BUGS
None reported... yet.
=cut