2012-04-01 9 views
1

私はftp_put()を使って別のサーバからファイルをダウンロードしています。すべて(接続など)は動作しますが、それはダウンロードされません。上記phpでファイルをダウンロードする

ftp_chdir($conn_id, $destination_file); 
    $upload = ftp_put($conn_id, $name, $source_file, FTP_BINARY); 

私のコードとその与えるエラー、それは私がftp_chdirを使用それほどうまくいかなかったとき、I OUT ftp_put「ftp_chdir」なし... 「にディレクトリを変更することはできません」です。まだ動作していません。 $destination_fileはパスに等しく、$nameはファイルに等しい。どうしたの? p.sでも$ uploadがtrueを返しています。しかし、私はどこにでもファイルを見つけることができません。

+2

FTP 'を入れて' アップロード... –

+1

http://php.net/ftp_put http://php.net/ftp_get – mishu

答えて

4

使用ftp_getはないftp_put

<?php 

// define some variables 
$local_file = 'local.zip'; 
$server_file = 'server.zip'; 

// 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 $server_file and save to $local_file 
if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) { 
    echo "Successfully written to $local_file\n"; 
} else { 
    echo "There was a problem\n"; 
} 

// close the connection 
ftp_close($conn_id); 

?> 

ftp_get from PHP manual

+0

感謝を誤解ビットを推測対です。しかし、今私はこのエラーが発生します。 'ストリームを開くことに失敗しました:そのようなファイルやディレクトリはありません.'と' Error opening'です。 :|どうして? – guitarlass

+0

は別の不器用なミスのようです。しかし、今度はこのエラーを受け取ります。ftp_get()[function.ftp-get]:http://example.com/folderx/foldery/test.zipを開くことができません:そのようなファイルやディレクトリはありません。\: – guitarlass

+0

@guitarlass – Songo

1

これは $source_file="http://example.com/ex/ex2/".$file_name;$destination_fileがパスに等しい、私のコードです。

 $conn_id = ftp_connect($ftp_server); 

    // login with username and password 
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

    // check connection 
    if ((!$conn_id) || (!$login_result)) { 
      echo "FTP connection has failed!"; 
      echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
      exit; 
     } else { 
      echo "Connected to $ftp_server, for user $ftp_user_name"; 
     } 

    // upload the file 
    //ftp_chdir($conn_id, $destination_file); 
    $upload = ftp_get($conn_id, $destination_file, $source_file, FTP_BINARY); 

    // check upload status 
    if (!$upload) { 
      echo "FTP upload has failed!"; 
     } else { 
      echo "Downloaded $source_file"; 
     } 

    // close the FTP stream 
    ftp_close($conn_id);*/ 
+1

$ ftp_serverの値は何ですか? – Songo

+0

とbtwは別々の答えではありません。それを見ることができます – Songo

+0

'$ ftp_server'は" example.xy.zo "のようなものです。ファイルアップロード/ダウンロードクライアントに入れたホスト名です。 – guitarlass

関連する問題