Local File Path
Posted: Fri Oct 08, 2004 4:17 pm
I am trying to FTP a file on my local drive (c:/...etc) to my remote server. All my code is correct except the local path. How does one reference a file on the local drive? In other words what is the correct syntax?
My code right now reads as follows:
$source_file = 'somefile.txt'
This is obviously incorrect because this says to search for 'somefile.txt' in the same directory as the .php file. Being that the .php file is on the remote server, it will look for 'somefile.txt' on the remote server. Again, I need to know what the code is to take a folder from a local drive. Thank you very much.
Just in case you wanted to see the entire script:
NOTE: "user" and "pw" are not the actual user name and password.
My code right now reads as follows:
$source_file = 'somefile.txt'
This is obviously incorrect because this says to search for 'somefile.txt' in the same directory as the .php file. Being that the .php file is on the remote server, it will look for 'somefile.txt' on the remote server. Again, I need to know what the code is to take a folder from a local drive. Thank you very much.
Just in case you wanted to see the entire script:
Code: Select all
<?php
// set up basic connection
$ftp_server = '63.135.102.252';
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = 'user';
$ftp_user_pass = 'pw';
$destination_file = 'newtextfile.txt';
$source_file = 'somefile.txt';
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if ((!$conn_id) || (!$login_result))
{echo "FTP connection has failed! <br>";
echo "Attempted to connect to $ftp_server for user $ftp_user_name <br>";
exit;}
else
{echo "Connected to $ftp_server for user $ftp_user_name <br>";}
// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload)
{echo "FTP upload has failed!";}
else
{echo "Uploaded $source_file to $ftp_server as $destination_file";}
// close the FTP stream
ftp_close($conn_id);
?>NOTE: "user" and "pw" are not the actual user name and password.