...

View Full Version : ftp_fget 'path' problem



david mccarthy
02-27-2008, 05:00 PM
I am trying to copy file from remote UNIX server to folder on 'C drive' on PC that is running webserver. I can copy to folder in htdocs on webserver, but what is the correct syntax to set path for download to folder 'POS' on C drive. The following path does not work...

This is my personal project - not 'commercial' (hi Aero! :) )




// path to remote file
$remote_header_file = 'PO'.$ponumber.'H';
$remote_detail_file = 'PO'.$ponumber.'D';


// path to local file
$local_file = 'C:/POS';


// open file to write to
$handle = fopen($local_file, 'w');


// download $remote_header_file and save it to $handle

if (ftp_fget($conn_id, $handle, $remote_header_file, FTP_ASCII, 0)) {
echo "$remote_header_file successfully written to $local_file\n at $time";
} else {
echo "There was a problem while downloading $remote_header_file to $local_file\n";

}

_Aerospace_Eng_
02-27-2008, 05:03 PM
Are you getting any errors? Run this function by it self outside of the if statement and see what it returns

ftp_fget($conn_id, $handle, $remote_header_file, FTP_ASCII, 0);
I don't know if it matters but you may have to switch your slashes though I think windows does both.

$local_file = 'C:\POS';

david mccarthy
02-27-2008, 05:17 PM
Thanks Aero -

I have now amended the code slightly, and the two files are being saved fine in 'C:/POS'. My only problem now is that they are being saved by the string name, i.e., $remote_header_file and $remote_detail_file.

I will have to keep tinkering... When I echo the string name, it prints the correct file name, ie. PO51234H and PO51234D.... odd!




// path to remote file
$remote_header_file = 'PO'.$ponumber.'H';
$remote_detail_file = 'PO'.$ponumber.'D';
$local_file_header = 'C:/POS/$remote_header_file';
$local_file_detail = 'C:/POS/$remote_detail_file';


// open file to write to
$handleH = fopen($local_file_header, 'w');

// download $remote_header_file and save it to $handle

if (ftp_fget($conn_id, $handleH, $remote_header_file, FTP_ASCII, 0)) {
echo "$remote_header_file successfully written to $local_file\n at $time";
} else {
echo "There was a problem while downloading $remote_header_file to $local_file\n";

}

?>

<html>
<br></html>

<?php

$handleD = fopen($local_file_detail, 'w');

// download $remote_detail_file and save it to $handle

if (ftp_fget($conn_id, $handleD, $remote_detail_file, FTP_ASCII, 0)) {
echo "$remote_detail_file successfully written to $local_file\n at $time";
} else {
echo "There was a problem while downloading $remote_detail_file to $local_file\n";

}

ftp_close($conn_id);

david mccarthy
02-27-2008, 05:19 PM
<?php
// path to remote file
$remote_header_file = 'PO'.$ponumber.'H';
$remote_detail_file = 'PO'.$ponumber.'D';
$local_file_header = 'C:/POS/$remote_header_file';
$local_file_detail = 'C:/POS/$remote_detail_file';


// open file to write to
$handleH = fopen($local_file_header, 'w');

// download $remote_header_file and save it to $handle

if (ftp_fget($conn_id, $handleH, $remote_header_file, FTP_ASCII, 0)) {
echo "$remote_header_file successfully written to $local_file\n at $time";
} else {
echo "There was a problem while downloading $remote_header_file to $local_file\n";

}

?>

<html>
<br></html>

<?php

$handleD = fopen($local_file_detail, 'w');

// download $remote_detail_file and save it to $handle

if (ftp_fget($conn_id, $handleD, $remote_detail_file, FTP_ASCII, 0)) {
echo "$remote_detail_file successfully written to $local_file\n at $time";
} else {
echo "There was a problem while downloading $remote_detail_file to $local_file\n";

}

ftp_close($conn_id);

_Aerospace_Eng_
02-27-2008, 05:23 PM
You need to use double quotes if you want the variables to parse. Try this

$local_file_header = "C:/POS/$remote_header_file";
$local_file_detail = "C:/POS/$remote_detail_file";
or you can do this

$local_file_header = 'C:/POS/'.$remote_header_file;
$local_file_detail = 'C:/POS/'.$remote_detail_file;

david mccarthy
02-27-2008, 05:30 PM
Aero.

I COULD KISS YOU!

You dont know how much you have helped me there - I would have been messing about for ages with that...

Your a diamond!

chat laters -

Dave



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum