perl小脚本——ftp上传文件、读取数据库表中数据

/* 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;
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28929558/viewspace-1170202/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28929558/viewspace-1170202/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值