M
M
Murad Jelilov2014-08-15 15:37:25
PHP
Murad Jelilov, 2014-08-15 15:37:25

Why doesn't ftp_put work?

Good afternoon, dear connoisseurs. When trying to upload a file to the server via ftp, this error occurs:
Warning: ftp_put(): listen() failed: Operation not permitted (1) in /public_html/test1.php on line 57
line $upload = ftp_put($conn_id, $ path, $filep, FTP_BINARY);
Switching to binary mode. in /public_html/test1.php on line 60 Error: FTP upload has failed!
someone explain what is happening)))
Fans send to Google, please do not disturb)))

<form action="test1.php" method="POST" enctype="multipart/form-data" >
 <table align="center">
 <tr>
 <td align="right">Current server:</td>
 <td><input size="50" type="text" name="server" value=""></td>
 </tr>
 <tr>
 <td align="right">Username:</td>
 <td><input size="50" type="text" name="user"  value="">
 </td>
 </tr>
 <tr>
 <td align="right">Password:</td>
 <td><input size="50" type="text" name="password" value="" ></td>
 </tr>
 <tr>
 <td align="right">Path on the Server:</td>
 <td><input size="50" type="text" name="pathserver" ></td>
 </tr>
 <tr>
 <td align="right">Select File to Upload:</td>
 <td><input name="userfile" type="file" size="50"></td>
 </tr>
 </table>
 <table align="center">
 <tr>
 <td align="center"><input type="submit" name="submit"></td>
 </tr>
 </table>
</form>

error_reporting(E_ALL);
$filep = $_FILES['userfile']['tmp_name']; 
$ftp_server = $_POST['server'];
$ftp_user_name = $_POST['user'];
$ftp_user_pass = $_POST['password']; 
$paths = $_POST['pathserver'];
$ftp_port= 21;
//имя файла на сервере после того, как вы его загрузите
$name = $_FILES['userfile']['name'];
$conn_id = ftp_connect($ftp_server,$ftp_port);
// входим при помощи логина и пароля
if($conn_id){
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);}
// проверяем подключение
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 </br>";
   }
   $path="/".$paths.'/'.$name;
 
// загружаем файл
 
$upload = ftp_put($conn_id, $path, $filep, FTP_BINARY);
// проверяем статус загрузки
if (!$upload) {
       echo "Error: FTP upload has failed!";
   } else{
       echo "Good: Uploaded $name to $ftp_server";
   }
ftp_close($conn_id);
set_time_limit(30);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2014-08-15
@dmuradz

The problem is lack of rights.
Use passive FTP mode
php.net/manual/en/function.ftp-pasv.php

D
Dmitry, 2014-08-15
@thewind

So there seems to be an error in variable naming...
and
we get $paths vs $path , path not found, upload failed.
Maybe this is the issue?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question