개발! 딱 깔끔하고 센스있게!

PHP-ftp-put+Copy 전체 폴더 구조 본문

개발 스크랩 메모/PHP

PHP-ftp-put+Copy 전체 폴더 구조

렉사이 2020. 12. 27. 02:42

FTP 스크립트를 만들기 위해 로컬 폴더 구조를 FTP 로 복사하려고 합니다.

기본적으로 사이트를 업데이트하기 위해서다.

나는 줄곧 아래의 코드를 테스트하고 있다 (이미 user/pass/domain) 을 변경하였으나 연결이 실패하지 않았고, 일이 정상적으로 되어 보였다.

 $server = 'ftp.domainname.co'; $ftp_user_name = 'user'; $ftp_user_pass = 'pass'; $dest = '.'; $source = '.'; $mode = 'FTP_ASCII'; $connection = ftp_connect($server); $login = ftp_login($connection, $ftp_user_name, $ftp_user_pass); if (!$connection || !$login) { die('Connection attempt failed!'); } $upload = ftp_put($connection, $dest, $source, $mode); if (!$upload) { echo 'FTP upload failed!'; } ftp_close($connection); 

나는 ftp-put 라인을 돌파할 자신이 있다.

나의 문제는:

  1. Can ftp_put upload an entire directory structure with files etc or is this just to upload one file at a time? Is there a different command I should be using?

  2. I think I have something wrong with these variables:

     $dest = '.'; $source = '.'; $mode = 'FTP_ASCII'; 

나는 양식이 옳다고 믿는다.

$dest-이것은 ftp 서버의 루트 디렉토리 ftp.domainname.co - 나는 ftp 서버를 여기에 놓아야 한다.

source-이것은 현재 로컬 경로입니다.

- 저도 완전한 C:etc 경로를 시도했습니다.

이 오류를 얻었습니다:경고: ftp put () 기대 인자 4는 길다

어떤 도움도 좋다.

감사합니다.

대답

그것은 디렉터리가 아니라 파일이 필요하기 때문이다.

ftput PHP 수첩에는 일부 코드 표시가 있어 주석자가 발표한 귀환 파일에 올립니다.

다음은 중 하나입니다 (주의하십시오. 완전한 경로가 필요합니다):

function ftp_putAll($conn_id, $src_dir, $dst_dir) { $d = dir($src_dir); while($file = $d->read()) { // do this for each file in the directory if ($file != "." && $file != "..") { // to prevent an infinite loop if (is_dir($src_dir."/".$file)) { // do the following if it is a directory if ([email protected]_chdir($conn_id, $dst_dir."/".$file)) { ftp_mkdir($conn_id, $dst_dir."/".$file); // create directories that do not yet exist } ftp_putAll($conn_id, $src_dir."/".$file, $dst_dir."/".$file); // recursive part } else { $upload = ftp_put($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY); // put the files } } } $d->close(); } 
Comments