[英]Downloading a file via ftp using php
I'm using ftp_put() to download a file from another server. 我正在使用ftp_put()从另一台服务器下载文件。 Everything (connection etc.) working but it wont download.
一切正常(连接等),但不会下载。
ftp_chdir($conn_id, $destination_file);
$upload = ftp_put($conn_id, $name, $source_file, FTP_BINARY);
above is my code and its giving error "Can't change directory to"... when i out ftp_put
without 'ftp_chdir' it didn't work so i used ftp_chdir
. 上面是我的代码及其给出的错误“无法将目录更改为” ...当我在没有'ftp_chdir'的情况下退出
ftp_put
时,它不起作用,因此我使用了ftp_chdir
。 but still not working. 但仍然无法正常工作。
$destination_file
equal to a path and $name
equal to a file. $destination_file
等于路径,而$name
等于文件。 Please give me an idea what ai doing wrong? 请给我一个想法,我做错了什么? ps even $upload is returning true.
ps,甚至$ upload返回true。 But i can't find the file anywhere.
但是我在任何地方都找不到文件。
Use ftp_get
not ftp_put
使用
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);
?>
This is my code, $source_file="http://example.com/ex/ex2/".$file_name;
这是我的代码,
$source_file="http://example.com/ex/ex2/".$file_name;
and $destination_file
is equal to a path. $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);*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.