download dan upload file ke ftp dengan php

Topik sebelumnya Topik selanjutnya Go down

download dan upload file ke ftp dengan php

Post by sukma on Wed 13 Aug 2008, 14:59

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);

?>

_________________
avatar
sukma
Moderator
Moderator

Jumlah posting : 123
Age : 30
Lokasi : Magelang
Registration date : 23.05.08

Lihat profil user http://www.masihbelajar.co.nr

Kembali Ke Atas Go down

Topik sebelumnya Topik selanjutnya Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik