由于某些奇怪的原因我无法连接到FTP服务器,任何人都可以帮助我吗?它的作用是告诉我它无法连接到ftp服务器。
<?php
// connect and login to FTP server
$ftp_server = "serverip";
$ftp_port = "22";
$ftp_username = "vpslogin";
$ftp_userpass = "vpspassword";
$ftp_conn = ftp_connect($ftp_server,$ftp_port) or die("Could Not Connect To FTP Server: "$ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$server_file = "directoy/listing";
// open local file to write to
$local_file = "local.txt";
$fp = fopen($local_file,"w");
// download server file and save it to open local file
if (ftp_fget($ftp_conn, $fp, $server_file, FTP_ASCII, 0))
{
echo "Successfully written to $local_file.";
}
else
{
echo "Error downloading $server_file.";
}
// close connection and file handler
ftp_close($ftp_conn);
fclose($fp);
?>
答案 0 :(得分:1)
你也忘记了第8行的结论
<?php
# FTP Info
$ftp_server = "serverip";
$ftp_username = "vpslogin";
$ftp_userpass = "vpspassword";
$ftp_conn = ftp_connect($ftp_server) or die("Could Not Connect To FTP Server: $ftp_server");
ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$server_file = "directoy/listing";
# Open Writable File
$local_file = "local.txt";
$fp = fopen($local_file,"w");
// download server file and save it to open local file
if (ftp_fget($ftp_conn, $fp, $server_file, FTP_ASCII, 0))
echo "Successfully written to $local_file.";
else
echo "Error downloading $server_file.";
# Close all
ftp_close($ftp_conn);
fclose($fp);