/* ftp上传文件 */
#!/usr/bin/perl-w
use strict;
use warnings;
#使用Net::FTP模块
use Net::FTP;
our $ftp_host = "10.55.15.232";
our $ftp_user = "username";
our $ftp_pw = "password";
&main();
exit(0);
sub main
{
&login_ftp();
}
sub login_ftp
{
my $ftp;
$ftp = Net::FTP->new($ftp_host,Passive=>1,Debug=>1,Timeout=>30) or die "Can not connect to ftp server $ftp_host : $@" , $ftp->message;
$ftp->login($ftp_user,$ftp_pw) or die "Can not login ", $ftp->message;;
$ftp->cwd("/test") or die "Can not change working directory !\n" , $ftp->message;
#$ftp->get("aaa.txt") or die "get failed ", $ftp->message;
$ftp->put("config.txt");
$ftp->quit;
}
=======================================================================
/* 读取数据库表中数据 */
#!/usr/bin/perl-w
use strict;
use warnings;
use DBI;
our $tnsname="criss";
our $username="zhangbin";
our $password="zhangbin";
our ($id ,$name);
print "This is a test for database connection !\n";
&main();
exit(0);
sub main
{
my $res=db_connect();
print "res = $res\n";
}
sub db_connect
{
my $sql=qq{select id, name from test1};
####数据库连接
my $dbh=DBI->connect("dbi:Oracle:$tnsname", $username, $password) or die "Can not connect db: $DBI::errstr\n";
my $sth=$dbh->prepare($sql) or die "prepare $sql failed : $DBI::errstr\n";
$sth->execute or die "execute $sql failed : $DBI::errstr\n";
$sth->bind_columns(undef,\$id,\$name);
#while(@arr = $sth->fetchrow_array())
#{
#print join ("\t",@arr),"\n";
#}
while($sth->fetch)
{
print "$id,$name\n"
}
$sth->finish;
####断开数据库连接
$dbh->disconnect() or warn "DB disconnect failed: $DBI::errstr\n";
return 100;
}
#!/usr/bin/perl-w
use strict;
use warnings;
#使用Net::FTP模块
use Net::FTP;
our $ftp_host = "10.55.15.232";
our $ftp_user = "username";
our $ftp_pw = "password";
&main();
exit(0);
sub main
{
&login_ftp();
}
sub login_ftp
{
my $ftp;
$ftp = Net::FTP->new($ftp_host,Passive=>1,Debug=>1,Timeout=>30) or die "Can not connect to ftp server $ftp_host : $@" , $ftp->message;
$ftp->login($ftp_user,$ftp_pw) or die "Can not login ", $ftp->message;;
$ftp->cwd("/test") or die "Can not change working directory !\n" , $ftp->message;
#$ftp->get("aaa.txt") or die "get failed ", $ftp->message;
$ftp->put("config.txt");
$ftp->quit;
}
=======================================================================
/* 读取数据库表中数据 */
#!/usr/bin/perl-w
use strict;
use warnings;
use DBI;
our $tnsname="criss";
our $username="zhangbin";
our $password="zhangbin";
our ($id ,$name);
print "This is a test for database connection !\n";
&main();
exit(0);
sub main
{
my $res=db_connect();
print "res = $res\n";
}
sub db_connect
{
my $sql=qq{select id, name from test1};
####数据库连接
my $dbh=DBI->connect("dbi:Oracle:$tnsname", $username, $password) or die "Can not connect db: $DBI::errstr\n";
my $sth=$dbh->prepare($sql) or die "prepare $sql failed : $DBI::errstr\n";
$sth->execute or die "execute $sql failed : $DBI::errstr\n";
$sth->bind_columns(undef,\$id,\$name);
#while(@arr = $sth->fetchrow_array())
#{
#print join ("\t",@arr),"\n";
#}
while($sth->fetch)
{
print "$id,$name\n"
}
$sth->finish;
####断开数据库连接
$dbh->disconnect() or warn "DB disconnect failed: $DBI::errstr\n";
return 100;
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28929558/viewspace-1170202/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28929558/viewspace-1170202/