#!D:/Perl/bin/perl.exe # FTPクライアントPerlスクリプトその1(Windowsサーバー専用BASP21版) # BASPftp1.pl 2002.08.21 作成:鷹の巣 http://sakaguch.com/ # BASP21.DLLの入手先は、http://www.hi-ho.ne.jp/babaq/basp21.html # 参考Webは、BASP21 FTPオブジェクト # http://www.hi-ho.ne.jp/babaq/basp21f.html #■□■ FTPサーバーの設定 ■□■ $FTPserver = 'example.com'; # FTPサーバーのホスト名。 $FTPuser = 'userID'; # FTP接続のユーザ名。 $FTPpass = 'password'; # FTP接続のパスワード。 $FTPtimeout = 60; # FTP接続待ち許容時間(秒) # FTPサーバーのディレクトリとファイル名の設定 $FTPremotedir = '/public_html'; # FTPサーバーに接続した後、change-directoryする場所 $FTPlocaldir = 'c:\temp'; # FTPクライアントのローカルフォルダ名 $FTPrfile = 'remote.txt'; # FTPサーバーのファイル名 $FTPlfile = 'local.txt'; # FTPクライアントのファイル名は、FTPサーバーのファイル名と同じにする。 $FTPremotefile = $FTPremotedir."/".$FTPrfile; # FTPサーバーのフルパスのファイル名 $FTPlocalfile = $FTPlocaldir."\\".$FTPlfile; # FTPクライアントのフルパスのファイル名 #■□■ FTPサーバー関係の設定終わり ■□■ use Win32::OLE; # OLEパッケージの使用 # Set ftp = WScript.CreateObject("basp21.FTP") ' WSH(Windows Scripting Host) $FTP = Win32::OLE -> new('basp21.FTP'); # Basp21オブジェクトの作成と変数の確保 # rc = ftp.Connect(svr,user,pass) # FTPサーバーに接続。タイムアウト省略値120秒 $rc = $FTP -> Connect($FTPserver.':21:'.$FTPtimeout,$FTPuser,$FTPpass); # FTPサービスポート番号21、ファイアーウォールは、省略。 # $rc=0:接続OK、1〜5:FTPエラー。(詳細は、GetReplyメソッドで。) # 10000以上:Winsock Error(典型的なエラーは 11001 ホスト名が見つからない) # $rc=-1:ソケットオープンエラー、-2 : タイムアウト print "Connect=$rc\n"; # 正常時は、0を表示。 # rc = ftp.GetFile(remote,local[,type]) # FTPサーバーからファイルを受信。文字("*")を使って複数ファイルを指定可能。 $rc = $FTP -> GetFile($FTPremotefile,$FTPlocaldir,0);# テキストファイルの受信 # 0:ASCII(省略値)。1:バイナリ。 # $rc=1以上:正常終了。受信したファイル数を表示。0:該当するファイルなし。 print "GetFile=$rc\n"; # 正常時は、1以上を表示。 # rc = ftp.PutFile(local,remote[,type]) # FTPサーバーへファイルを送信。文字("*")を使って複数ファイルを指定可能。 $rc = $FTP -> PutFile($FTPlocalfile,$FTPremotedir,0);# テキストファイルの送信 # 0:ASCII(省略値)。1:バイナリ。2:ASCII+追加(Append)モード。3:バイナリ+追加(Append)モード。 # $rc=1以上:正常終了。送信したファイル数を表示。0:該当するファイルなし。 print "PutFile=$rc\n"; # 正常時は、1以上を表示。 # ftp.Close $FTP -> Close; # 接続を切断します。