Zac123
asked on
save .csv file to a particular directory
Hello,
the code below is fetching a csv file for me from an FTP account. it works fine except that it totally ignores where i want the csv file to be saved.
where is says 'YOUR FOLDER PATH' i've been putting in here C:inetpub\wwwroot\mydomain \temp
but instead of putting it in the /temp dir it just dropps the csv file in the same dir as from where the script is run from which is a completly different dir.
any ideas?
thanks
zac
the code below is fetching a csv file for me from an FTP account. it works fine except that it totally ignores where i want the csv file to be saved.
where is says 'YOUR FOLDER PATH' i've been putting in here C:inetpub\wwwroot\mydomain
but instead of putting it in the /temp dir it just dropps the csv file in the same dir as from where the script is run from which is a completly different dir.
any ideas?
thanks
zac
<?php
// define some variables
$folder_path = "YOUR FOLDER PATH";
$local_file = "the_file.csv";
$server_file = "the_file.csv";
//-- Connection Settings
$ftp_server = "IP ADDRESS"; // Address of FTP server.
$ftp_user_name = "USERNAME"; // Username
$ftp_user_pass = "PASSWORD"; // Password
#$destination_file = "FILEPATH";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($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);
?>
ASKER
thanks so is this the web path or the actual server path like:
C:\inetpub\wwwroot\etc etc etc
sorry, this is my first ever attempt at PHP
C:\inetpub\wwwroot\etc etc etc
sorry, this is my first ever attempt at PHP
<?php
// define some variables
$folder_path = "C:\Inetpub\Www_root\mydomain\temp";
$local_file = "file.csv";
$server_file = "file.csv";
//-- Connection Settings
$ftp_server = "ftp.server.co.uk"; // Address of FTP server.
$ftp_user_name = "user"; // Username
$ftp_user_pass = "pass"; // Password
#$destination_file = "FILEPATH";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download $server_file and save to $local_file
if (ftp_get($conn_id, $folder_path . $local_file, $server_file, FTP_BINARY))
with $folder_path = "C:\Inetpub\Wwwroot\mydomain\temp"; {
echo "Successfully written to $local_file\n";
} else {
echo "There was a problem\n";
}
// close the connection
ftp_close($conn_id);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
well done that man! perfect, thank you.
zac
zac
You're welcome! Thanks for the points and Merry Christmas!
http://www.php.net/manual/en/function.ftp-get.php
line 20 :
if (ftp_get($conn_id, $folder_path . $local_file, $server_file, FTP_BINARY))
with $folder_path = "/path/to/folder/";
Regards.