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;
}
#!/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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 如何建立最簡單的 ABAP 資料庫表,以及編碼從資料庫表中讀取資料 (上)資料庫
- 使用openpyxl庫讀取Excel檔案資料Excel
- EasyExcel庫來讀取指定Excel檔案中的資料Excel
- 讀取資料夾檔案
- Excel上傳並讀取資料Excel
- http不使用Form表單傳送檔案資料和非檔案資料(上傳篇)HTTPORM
- Java讀取properties檔案連線資料庫Java資料庫
- 使用yaml檔案讀取資料YAML
- ajax讀取資料庫資料程式碼例項資料庫
- 前端讀取Excel表中資料前端Excel
- 【Git/Github】向已有倉庫上傳檔案/資料夾Github
- sqlserver讀取oracle資料庫資料SQLServerOracle資料庫
- 利用反射讀取資料庫資料反射資料庫
- 資料庫建表和上線指令碼常見規範資料庫指令碼
- PHP ftp上傳檔案PHPFTP
- golang讀取檔案的json資料流,並解析到struct,儲存到資料庫GolangJSONStruct資料庫
- Kettle 從資料庫讀取資料存到變數中資料庫變數
- 說說在 Python 中,如何讀取檔案中的資料Python
- 如何在Shell指令碼中逐行讀取檔案指令碼
- C# 操縱貼上板 Clipboard(傳送資料、讀取資料、清空資料)C#
- 使用shell指令碼替換csv檔案中的資料指令碼
- eazyexcel 讀取excel資料插入資料庫Excel資料庫
- gin框架,讀取檔案的json資料流,並解析到struct,儲存到資料庫框架JSONStruct資料庫
- 使用ajax指令碼取資料指令碼
- laravel、lumen等.env檔案資料庫密碼配置正確,連不上資料庫Laravel資料庫密碼
- python中按照資料夾中檔案的排列順序讀取檔案內容Python
- 定時ftp上傳,如何設定定時ftp上傳檔案FTP
- EAS附件表由資料庫遷移到FTP資料庫FTP
- C# exe上傳檔案和提交表單資料的方法C#
- ASP.NET Core 中的檔案提供程式 遍歷資料夾讀取檔案資訊ASP.NET
- 資料庫備份指令碼資料庫指令碼
- mssql sqlserver 使用sql指令碼 清空所有資料庫表資料的方法分享SQLServer指令碼資料庫
- AJAX資料互動及檔案上傳功能
- SpringMVC(四)上傳檔案、json資料互動SpringMVCJSON
- Laravel file 上傳檔案資訊獲取Laravel
- laravel file上傳檔案資訊獲取Laravel
- 【TcaplusDB知識庫】PB表 C++ 示例程式碼-讀取資料C++
- 網站檔案修改資料庫,安全高效地修改網站資料庫中的檔案資訊網站資料庫
- 如何將資料庫中的資料導成 excel 檔案資料庫Excel