Ftp error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ratan
Forum Commoner
Posts: 28
Joined: Thu Jul 13, 2006 4:22 pm

Ftp error

Post by ratan »

JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello, I am trying to download files from a ftp server.  I see the icon of the file in my local directory with 0KB, after which the script
fails and the icon disappears.  I have used windows copy/paste from the FTP site and that works. So, I am not sure what
is the problem here. I am attaching my script. Pls. help.

Code: Select all

$arrFiles = array();
$arrFiles[] = fileNameCreator("file1", "csv");
$arrFiles[] = fileNameCreator("file2", "csv");
$arrFiles[] = fileNameCreator("file3", "csv");

$conn = ftp_connect($HOST,$PORT);
if(!$conn) 
{
	exit("Could not connect to server: $HOST\n");
}

if(!ftp_login($conn,$UN,$PW)) 
{        
	ftp_quit($conn);
   	exit("Could not log in\n");
}
ftp_chdir($conn,$DIR);


foreach($arrFiles as $aF)
{
	$FILE_LOCAL = "C:\tempDir\\".$aF;
	if(!ftp_get($conn,$FILE_LOCAL,$aF,FTP_ASCII)) 
	{
    	echo "Successfully written to $FILE_LOCAL\n";
    } 
    else 
    {
    	echo "There was a problem\n";
    }
}



  ftp_quit($conn);

JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ratan
Forum Commoner
Posts: 28
Joined: Thu Jul 13, 2006 4:22 pm

Post by ratan »

It works now..I replaced ftp_get() with file_get_contents()....Thanks!!
Post Reply