download dan upload file ke ftp dengan php
most-c :: Pemrograman :: PHP, CSS, HTML
Halaman 1 dari 1
download dan upload file ke ftp dengan php
download :
<?php
$remote_file = "file_awal/file.txt";
$local_file = "file_tujuan/file_baru.txt";
$handle = fopen($local_file, 'w');
// Global Connection Settings
$ftp_server = "localhost"; // FTP Server Address (exlucde ftp://)
$ftp_user_name = "***"; // FTP Server Username
$ftp_user_pass = "***"; // Password
// Connect to FTP Server
$conn_id = ftp_connect($ftp_server);
// Login to FTP Server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $remote_file and save it to $handle
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
echo "successfully written to $local_file\n";
} else {
echo "There was a problem while downloading $remote_file to $local_file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($handle);
?>
Sebagai contohnya saya siapkan source code nya..
syarat :
- port FTP open
- ada user yg bisa ngeakses path file
- sudah tentu permision user tersebut like root
yg akan terjadi :
- file.txt yg terdapat di folder file_awal
- akan tercopy menjadi file_baru.txt di dalam folder file tujuan
upload :
<?php
// set up the settings
$ftp_server = 'something.net';
$ftpuser = 'username';
$ftppass = 'pass';
// delete the below variables if you decide to use a form.
$source_file = 'blah blah/blah.txt';
$destination_file = 'blah blah/blah.txt';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);
ftp_put($conn_id, “$destination_file”, “$source_file”, FTP_BINARY); // the ftp function
// close the connection
ftp_close($conn_id);
?>
<?php
$remote_file = "file_awal/file.txt";
$local_file = "file_tujuan/file_baru.txt";
$handle = fopen($local_file, 'w');
// Global Connection Settings
$ftp_server = "localhost"; // FTP Server Address (exlucde ftp://)
$ftp_user_name = "***"; // FTP Server Username
$ftp_user_pass = "***"; // Password
// Connect to FTP Server
$conn_id = ftp_connect($ftp_server);
// Login to FTP Server
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $remote_file and save it to $handle
if (ftp_fget($conn_id, $handle, $remote_file, FTP_ASCII, 0)) {
echo "successfully written to $local_file\n";
} else {
echo "There was a problem while downloading $remote_file to $local_file\n";
}
// close the connection and the file handler
ftp_close($conn_id);
fclose($handle);
?>
Sebagai contohnya saya siapkan source code nya..
syarat :
- port FTP open
- ada user yg bisa ngeakses path file
- sudah tentu permision user tersebut like root
yg akan terjadi :
- file.txt yg terdapat di folder file_awal
- akan tercopy menjadi file_baru.txt di dalam folder file tujuan
upload :
<?php
// set up the settings
$ftp_server = 'something.net';
$ftpuser = 'username';
$ftppass = 'pass';
// delete the below variables if you decide to use a form.
$source_file = 'blah blah/blah.txt';
$destination_file = 'blah blah/blah.txt';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppass);
ftp_put($conn_id, “$destination_file”, “$source_file”, FTP_BINARY); // the ftp function
// close the connection
ftp_close($conn_id);
?>
Similar topics
» sms gateway dengan gambas
» membuat jam dengan java script
» Pembatasan badwith dengan Squid
» Setting FTP Server dengan ProFTPD di Linux Slackware
» Internet dengan Modem Ponsel GPRS dan CDMA
» membuat jam dengan java script
» Pembatasan badwith dengan Squid
» Setting FTP Server dengan ProFTPD di Linux Slackware
» Internet dengan Modem Ponsel GPRS dan CDMA
most-c :: Pemrograman :: PHP, CSS, HTML
Halaman 1 dari 1
Permissions in this forum:
Anda tidak dapat menjawab topik