Created
October 5, 2017 09:33
-
-
Save dertajora/a6522f53634579940728cf0934bf391a to your computer and use it in GitHub Desktop.
Upload file Via FTP using PHP
This file contains hidden or 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
// FTP access parameters | |
$host = 'xxx'; | |
$usr = 'xxx'; | |
$pwd = 'xxx'; | |
// file to move: | |
// $local_file = 'D:/xampp/htdocs/absen_folder/log_script.txt'; | |
// $local_file = 'D:\xampp\htdocs\absen_folder\log_script.txt'; | |
$local_file = 'cek.txt'; | |
$ftp_path = 'derta.co.id/htdocs/tes_derta/'.date('Y-m-d').'/cek.txt'; | |
$dir = 'derta.co.id/htdocs/tes_derta/'.date('Y-m-d').'/'; | |
// connect to FTP server (port 21) | |
$conn_id = ftp_connect($host, 21) or die ("Cannot connect to host"); | |
// send access parameters | |
ftp_login($conn_id, $usr, $pwd) or die("Cannot login"); | |
// turn passive mode on | |
ftp_pasv($conn_id, true); | |
// create directory in FTP | |
if (ftp_mkdir($conn_id, $dir)){ | |
echo "Successfully created $dir"; | |
}else{ | |
echo "Error while creating $dir"; | |
} | |
// perform file upload via FTP | |
$upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII); | |
if ($upload) { | |
echo "Successfully uploaded $local_file\n"; | |
} else { | |
echo "There was a problem with uploading $local_path"."<br>"; | |
} | |
// close the FTP stream | |
ftp_close($conn_id); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment