[英]download file from remote server by php?
有人告訴我。 我是否可以通過 php 從我所在位置的遠程服務器下載特定文件?
我試過密碼但我不能
<?php
// define some variables
$local_file = '/httpdocs/teste.pdf';
$server_file = 'teste.pdf';
$ftp_server="209.126.127.143";
$ftp_user_name="username";
$ftp_user_pass="password";
$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);
?>
我不認為你可以下載一個文件夾。 嘗試在$server_file
中包含文件名
ftp_get($conn_id, './teste.pdf', '/httpdocs/teste.pdf', FTP_BINARY)
此外, /httpdocs/
應該與您的 FTP 用戶的主文件夾相關
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.