Debt Consolidation - Debt Consolidation - Creative Electronics - Debt Consolidation - Gavin Newsom

PDA

View Full Version : Move file from FTP to server


inderpal
Jun 21st 2007, 12:02 pm
Hi All,

I have a file on FTP (it could be on any FTP server, will have username and password).

I need to download it from FTP and upload it to my web server (in backend process only).

I have a button in admin panel. When I click on that, file should be moved from FTP to the pre-defined server location. Is there any direct way to achive this?

Thanks in advance.......

Regards,
Inderpal Singh

krakjoe
Jun 21st 2007, 12:14 pm
<?php
define("FTP_SERVER", 'krakjoe.com');
define("FTP_TIMEOUT", 5 );
define("FTP_PORT", 21 );
define("FTP_USERNAME", 'username');
define("FTP_PASSWORD", 'password');
define("FTP_FILE", '/www/index.php');
define("SCRIPT_SAVE_AS", 'test.php');

class ftp
{
function ftp( )
{
if( !( $this->con = ftp_connect( FTP_SERVER, FTP_PORT, FTP_TIMEOUT ) ) )
{
die( sprintf( "Cannot establish ftp connect @ %s on port %d", FTP_SERVER, FTP_PORT ) );
}
elseif( !ftp_login( $this->con, FTP_USERNAME, FTP_PASSWORD ) )
{
die( sprintf( "Cannot login @ %s with %s and supplied password", FTP_SERVER, FTP_USERNAME ) );
}
}
function get( )
{
return ftp_get( $this->con, SCRIPT_SAVE_AS, FTP_FILE, FTP_BINARY );
}
function close( )
{
return ftp_closE( $this->con );
}
}
$ftp = new ftp( );

if( $_POST )
{
if( $ftp->get( ) )
{
printf("File saved @ %s", SCRIPT_SAVE_AS );
}
else
{
printf("Cannot download %s from %s", FTP_FILE, FTP_SERVER );
}
}
?>
<html>
<head>
<title>Grab file from ftp using button</title>
</head>
<body>
<form action="" method="post">
<input type="submit" name="action" value="Submit">
</form>
</body>
</html>

inderpal
Jun 21st 2007, 1:04 pm
Thanks krakjoe for your help. That script of yours works like a charm.

Thanks again.....

krakjoe
Jun 21st 2007, 1:09 pm
always a pleasure .... :)