Skip to content

Instantly share code, notes, and snippets.

@ashokdhaduk
Forked from tanmay27vats/function.php
Created May 28, 2018 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashokdhaduk/21fd6ca97d65882431596073a8e4b38d to your computer and use it in GitHub Desktop.
Save ashokdhaduk/21fd6ca97d65882431596073a8e4b38d to your computer and use it in GitHub Desktop.
How to upload local file on the FTP/SFTP server - PHP
// 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