Created
July 23, 2024 05:27
-
-
Save alexlatam/2de64eaa779f3d83695046695f68c5d3 to your computer and use it in GitHub Desktop.
FTP Connection using PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Session data | |
$ftpHost = 'ftp.domain.ext'; | |
$ftpUsername = 'username'; | |
$ftpPassword = '*****'; | |
// Connect with ftp host | |
$conn = ftp_connect($ftpHost) or die("Is not possible connect with ftp host"); | |
// Login with ftp host | |
$ftpLogin = ftp_login($conn, $ftpUsername, $ftpPassword); | |
// SEND FILE TO FTP SERVER | |
$localFilePath = "index.php"; | |
$remoteFilePath = "public/index.php"; | |
if(ftp_put($conn, $remoteFilePath, $localFilePath, FTP_ASCII)) { | |
echo "File transferred successfully"; | |
} | |
// GET FILE FROM FTP SERVER | |
if(ftp_get($conn, $localFilePath, $remoteFilePath, FTP_BINARY)) { | |
echo "File transferred successfully"; | |
} | |
// DELETE FILE FROM FTP SERVER | |
if(ftp_delete($conn, $localFilePath, $remoteFilePath, FTP_BINARY)) { | |
echo "File transferred successfully"; | |
} | |
// close FTP session | |
ftp_close($conn); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment