Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP FAQs
|
PHP FAQs This moderated forum is where our PHP experts answer some of the questions they see asked most frequently in the other PHP forums. You cannot post other messages here, use the other PHP forums for that.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP FAQs section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2007, 03:56 PM
Guest
 
Posts: n/a
Default transferring files via FTP from my remote

I have not been successful transferring files via FTP from my remote server to my local windows machine using the following code.

 $ftpserver = "ftp Server";
 $ftpdirectory = "image_specs.txt";
 $download = "C:\\testFTP\\Another Directory";
 $tempfile = tempnam("tmp", "ftp");
 $destdir = "C:\\";
 if (!($ftp = ftp_connect($ftpserver))) { print("Unable to connect to $ftpserver!<br>\n");
 }
 print("Connected to $ftpserver…<br>\n");
 if (!ftp_login($ftp, "user", "pass")) { print("Unable to login.<br>\n");
 }
 print("Logged in.<br>\n");
 ftp_pasv($ftp, FALSE);
 //if(!ftp_chdir($ftp, $ftpdirectory)) { print("Unable to change directory to $ftpdirectory!<br>\n"); exit();
 //}
 $fp = fopen($tempfile, 'w');
 if(!ftp_fget($ftp, $fp, $download, FTP_ASCII)) { print("Unable to download file $download!<br>\n"); exit();
 }
 if(!rename($tempfile, $destdir . "C:\\" . $download)) { print("Unable to move file to destination directory!<br>\n"); exit();
 }
 print("File $download successfully downloaded.<br>\n");
}

or

function ftpFiles ()
{
$conn = ftp_connect("ftp Server") or die("Could not connect");
ftp_login($conn,"user", "pass");
echo ftp_get($conn,"C:\testFTP","image_specs.txt",FTP_A SCII);
ftp_close($conn);
}

or

function downLoad2 ()
{
// define some variables
$local_file = 'C:\testFTP\\';
$server_file = 'image_specs.txt';

// set up basic connection
$conn_id = ftp_connect("ftp Server");

// login with username and password
$login_result = ftp_login($conn_id, "user", "pass");

// try to download $server_file and save to $local_file
if (ftp_fget($conn_id, $local_file, $server_file, FTP_BINARY)) {
   echo "Successfully written to $local_file\n";
} else {
   echo "There was a problem\n";
}

// close the connection
ftp_close($conn_id);

}

The file is being transferred to the remote server. I need to save the file locally. Please help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
[Closed] FTP to Remote Server snufse ASP.NET 2.0 Basics 2 March 7th, 2008 01:17 PM
Transferring files sachtaridis Visual C++ 0 November 22nd, 2007 07:31 AM
Transferring files to ftp server mar4ik Servlets 0 September 14th, 2006 06:15 AM
Transferring xml files between servers over http. s_a_ravi General .NET 0 March 29th, 2005 09:37 AM
Transfer Files via FTP vb_developer C# 2 September 8th, 2004 12:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.