【发布时间】:2020-01-22 18:51:32
【问题描述】:
有人告诉我。我是否可以通过 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);
?>
【问题讨论】:
-
您是否收到任何错误,您为调试问题做了什么?
-
在我所在位置的远程服务器上下载文件时收到此错误> 警告:ftp_get(/httpdocs/teste.pdf):无法打开流:/Applications/XAMPP 中没有此类文件或目录/xamppfiles/htdocs/LDL/api/ftpdow.php 在第 16 行警告:ftp_get(): Error opening /httpdocs/teste.pdf in /Applications/XAMPP/xamppfiles/htdocs/LDL/api/ftpdow.php on line 16 那里是个问题
-
httpdocs != htdocs -
您可以使用任何 (GUI) FTP 客户端使用相同的凭据下载该文件吗? => 向我们展示它的日志文件。