<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$ftpServer = 'ftp://123.website.com';
$ftpUsername = 'username';
$ftpPassword = 'password';
$remotePath = $_POST['remotePath'];
$fileToUpload = $_FILES['fileToUpload']['tmp_name'];
$fileExtension = $_FILES['fileToUpload']['type'];
$fileName = $_POST['file_name'] . '.' . $fileExtension;
$conn = ftp_connect($ftpServer, 80);
if ($conn) {
$login = ftp_login($conn, $ftpUsername, $ftpPassword);
if ($login) {
if (ftp_put($conn, $remotePath . $fileName, $fileToUpload, FTP_BINARY)) {
echo "<p>File upload succesfull</p>";
} else {
echo "<p>Error when uploading file</p>";
}
ftp_close($conn);
} else {
echo "<p>FTP-Login failed</p>";
}
} else {
echo "<p>Couldnt connect to FTP server</p>";
}
}
?>
我得到
无法连接到FTP服务器
港口是80。我可以用正确的登录信息打开FTP服务器。是什么让我无法与之连接?
1条答案
按热度按时间yc0p9oo01#
ftp_connect
的hostname
参数采用 hostname(或IP地址),而不是URL。所以应该是: