Is it possible to upload files from FTP to FTP using PHP
Here is my prob in Brief.
I know how to upload a file to server using FTP with programming language PHP.
But is that possible to get files from another server to our server using PHP with
having the FTP Username and Passwo开发者_JAVA技巧rd
Thanks n advance...
Fero
Yes, you can fetch files from FTP using PHP - using ftp_get
.
The following snippet is from the documentation:
$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";
}
Technically, the FTP protocol allows for server-to-server transfers, called FXP. This feature is disabled by default on most FTP servers, though, for security reasons, so you would need to be able to verify/enable it before it would work.
If it is enabled, you should just need to script the FXP commands and everything should work fine.
Here's a link to a promising function:
http://www.php.net/manual/en/function.ftp-fget.php
You'll need to open the local file up for dumping into, and manage the connection and whatnot, but this is the way to do it.
I don't think it's much different from copying a file from a directory to another, provided that you know how to open a file in an FTP Server..
精彩评论