Created
January 21, 2018 16:07
-
-
Save tanmay27vats/aefd12f1603d774de3c6f3f207182ada to your computer and use it in GitHub Desktop.
How to upload local file on the FTP/SFTP server - 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
// connect and login to FTP server | |
$ftp_server = "ftp.domain.com"; | |
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); | |
//$ftp_conn = ftp_ssl_connect($ftp_server);// for SSL-FTP connection instead of ftp_connect | |
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass); | |
$file = "local-file.jpg"; | |
// upload file | |
if (ftp_put($ftp_conn, "server-file.jpg", $file, FTP_ASCII)) { | |
echo "Successfully uploaded $file."; | |
} else { | |
echo "Error uploading $file."; | |
} | |
// close connection | |
ftp_close($ftp_conn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment