IT/php

php ftp_fget - FTP 서버에서 파일을 다운로드하고 열려있는 파일에 저장합니다.

조원태 2017. 2. 13. 01:15
반응형

ftp_fget - FTP 서버에서 파일을 다운로드하고 열려있는 파일에 저장합니다.


설명 ¶


bool ftp_fget ( resource $ftp_stream , resource $handle , string $remote_file , int $mode [, int $resumepos= 0 ])

ftp_fget ()는 검색remote_file FTP 서버에서 주어진 파일 포인터에 기록합니다.


매개 변수 ¶


ftp_stream

FTP 연결의 링크 식별자입니다.


handle

우리가 데이터를 저장하는 열린 파일 포인터.


remote_file

원격 파일 경로입니다.


mode

전송 모드. FTP_ASCII또는 중 하나 여야합니다 FTP_BINARY.


resumepos

원격 파일에서 다운로드를 시작할 위치입니다.


반환 값 ¶


반환 값 TRUE성공 또는 FALSE실패.


예 ¶


Example # 1 ftp_fget () 예제


<?php


// path to remote file

$remote_file = 'somefile.txt';

$local_file = 'localfile.txt';


// open some file to write to

$handle = fopen($local_file, 'w');


// set up basic connection

$conn_id = ftp_connect($ftp_server);


// login with username and password

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);


// try to download $remote_file and save it to $handle

if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {

 echo "successfully written to $local_file\n";

} else {

 echo "There was a problem while downloading $remote_file to $local_file\n";

}


// close the connection and the file handler

ftp_close($conn_id);

fclose($handle);

?>

반응형