Search code examples
phpftpmkdirftps

Connect to Server via PHP and Write File


I am trying to connect to a server via php and write a PDF file to a folder that I dynamically create. This is the code I am using:

<?php
$ftp_server = "[server ip]";
$ftp_user_name = "[username]";
$ftp_user_pass = "[password]";

// set up basic ssl connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
if ($login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)){

mkdir('/home/luke/public_html/pdfs/kmhllc/', 0777, true);
}else{
echo "Connection Failed";
}
// close the ssl connection
ftp_close($conn_id);
?>`

The code connects to the server just fine but it can't write to the folder even though it has 0777 permissions on the server.


Solution

  • use ftp_mkdir not mkdir to create a directory on the ftp server.