ftp 접속하고 목록 뽑아서 파일 복사해오기

렛츠웹 + 게임/My Tip 2009. 1. 5. 17:04

<?

$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
 //echo "Connected as $ftp_user@$ftp_server\n";
} else {
 echo "Couldn't connect as $ftp_user\n";
}


// turn passive mode on
ftp_pasv($conn_id, true);


$files = ftp_nlist($conn_id, "/");


for($i=0;$i<sizeof($files);$i++)
{

 $x_n=$files[$i];
 //echO "$x_n <br>";
 $local_file='/data/news/cron/aving/'.$x_n;
 $server_file=$x_n;
 if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
      echo "Successfully written to $local_file<br>";
 } else {
     echo "There was a problem $local_file <br>";
 }
 
 if (ftp_delete($conn_id, $x_n)) {
  echo "$file deleted successful $x_n<br><br>";
 } else {
   echo "could not delete $x_n<br><br>";
 } 

}

?>


'렛츠웹 + 게임 > My Tip' 카테고리의 다른 글

트리메뉴  (0) 2009.01.05
디렉토리에서 파일 목록 추출해서 돌리고 삭제하기  (0) 2009.01.05
계급아이콘,아바타  (0) 2009.01.05
보드생성 관리 소스  (0) 2009.01.05
[Mysql] FEDERATED Tables (DB Link)  (0) 2009.01.05
posted by 망차니

설정

트랙백

댓글

계급아이콘,아바타

렛츠웹 + 게임/My Tip 2009. 1. 5. 17:03
posted by 망차니

설정

트랙백

댓글

보드생성 관리 소스

렛츠웹 + 게임/My Tip 2009. 1. 5. 17:02

'렛츠웹 + 게임 > My Tip' 카테고리의 다른 글

ftp 접속하고 목록 뽑아서 파일 복사해오기  (0) 2009.01.05
계급아이콘,아바타  (0) 2009.01.05
[Mysql] FEDERATED Tables (DB Link)  (0) 2009.01.05
urlencode urldecode  (0) 2009.01.05
위로 스크롤 되는 배너  (0) 2009.01.05
posted by 망차니

설정

트랙백

댓글

[Mysql] FEDERATED Tables (DB Link)

렛츠웹 + 게임/My Tip 2009. 1. 5. 17:02
Mysql 5.0에서 새로 생긴 기능인 "FEDERATED Tables"은 기존의 Oracle이나 MS-Sql에서는 이미 익숙한 기능인 Database Link기능과 비슷한 성격을 가지고 있다. (Database 단위로 링크하는 기능은 아직 없고, Table 단위로 링크를 한다는 점이 다름)

Federated Tables기능을 사용하기 위해서는 Mysql 컴파일시 Configure에서 "-with-federated-storage-engine " 옵션을 주어야 한다. (MySQL 5.0.3 or newer. )

동일 서버 또는 원격지 서버 데이터베이스의 Table을 링크 할 수 있으며 사용방법은 다음과 같다.

■ 동일 서버 또는 원격지 서버의 Table
CREATE TABLE test_table (
    id     INT(20) NOT NULL AUTO_INCREMENT,
    name   VARCHAR(32) NOT NULL DEFAULT '',
    other  INT(20) NOT NULL DEFAULT '0',
    PRIMARY KEY  (id),
    INDEX name (name),
    INDEX other_key (other)
)
ENGINE=MyISAM
DEFAULT CHARSET=latin1;


■ Federated Table 생성
CREATE TABLE federated_table (
    id     INT(20) NOT NULL AUTO_INCREMENT,
    name   VARCHAR(32) NOT NULL DEFAULT '',
    other  INT(20) NOT NULL DEFAULT '0',
    PRIMARY KEY  (id),
    INDEX name (name),
    INDEX other_key (other)
)
ENGINE=FEDERATED
DEFAULT CHARSET=latin1
CONNECTION='mysql://root@remote_host:9306/federated/test_table';

Connection String을 구성하는 방법은 아래와 같다.

CONNECTION='mysql://username:password@hostname:port/database/tablename'
CONNECTION='mysql://username@hostname/database/tablename'
CONNECTION='mysql://username:password@hostname/database/tablename'

※ Federated Tables의 취약점이라고 한다면 서버의 ID/Password가 노출된다는 점(?)이랄까?
posted by 망차니

설정

트랙백

댓글

urlencode urldecode

렛츠웹 + 게임/My Tip 2009. 1. 5. 16:57

//urlencode
function URLEncode(txt)
{
 // The Javascript escape and unescape functions do not correspond
 // with what browsers actually do...
 var SAFECHARS = "0123456789" +     // Numeric
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
     "abcdefghijklmnopqrstuvwxyz" +
     "-_.!~*"()";     // RFC2396 Mark characters
 var HEX = "0123456789ABCDEF";

 var plaintext = txt;
 var encoded = "";
 for (var i = 0; i < plaintext.length; i++ ) {
  var ch = plaintext.charAt(i);
     if (ch == " ") {
      encoded += "+";    // x-www-urlencoded, rather than %20
  } else if (SAFECHARS.indexOf(ch) != -1) {
      encoded += ch;
  } else {
      var charCode = ch.charCodeAt(0);
   if (charCode > 255) {
       alert( "Unicode Character ""
                        + ch
                        + "" cannot be encoded using standard URL encoding.n" +
              "(URL encoding only supports 8-bit characters.)n" +
        "A space (+) will be substituted." );
    encoded += "+";
   } else {
    encoded += "%";
    encoded += HEX.charAt((charCode >> 4) & 0xF);
    encoded += HEX.charAt(charCode & 0xF);
   }
  }
 } // for

 return encoded;
};

function URLDecode(txt)
{
   // Replace + with " "
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var encoded = txt;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
    if (ch == "+") {
        plaintext += " ";
     i++;
    } else if (ch == "%") {
   if (i < (encoded.length-2)
     && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
     && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
    plaintext += unescape( encoded.substr(i,3) );
    i += 3;
   } else {
    alert( "Bad escape combination near ..." + encoded.substr(i) );
    plaintext += "%[ERROR]";
    i++;
   }
  } else {
     plaintext += ch;
     i++;
  }
 } // while
   return plaintext;
};


posted by 망차니

설정

트랙백

댓글