Example 1 — Create a Remote Folder
Log in and create a folder named uploads on the server.
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'username', 'password');
$dir = ftp_mkdir($ftp, 'uploads');
if ($dir !== false) {
echo "Created: ", $dir, PHP_EOL;
}
ftp_close($ftp); How It Works
- The script connects and logs in first, because ftp_mkdir() needs a logged-in session.
- ftp_mkdir() asks the server to create the uploads directory.
- The returned name is stored in $dir.
- The strict check !== false confirms the folder was created.

