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!
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have the following code, which works as far as connecting to the FTP site but doesn't upload the file. When the code runs, this is the message that is received:
Connected to ftp.transparentvalue.com, for user user. FTP upload has failed!
I can't figure out for the life of me why this won't work. All the code seems to be in order. If someone could help me, it would mean the world to me. Thank you.
<?php
// set up basic connection
$ftp_server = 'ftp.transparentvalue.com';
$conn_id = ftp_connect($ftp_server);
$ftp_user_name = 'user';
$ftp_user_pass = 'pw';
$destination_file = 'somefile.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!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;}
else
{echo "Connected to $ftp_server, for user $ftp_user_name";}
// 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);
?>
Perhaps it has to do with the file paths?
Or maybe it is a server-side problem? (i.e. does not allow external FTP -
I use Dreamweaver right now to FTP my files directly)
the fact that you are connecting will dismiss the idea of serve configurations and the fact that you use dreamweaver to ftp sites now.
is 'somefile.txt' in the same directory as your script, try putting the full path ie.
c:\some\directory\path\somefile.txt
and see if it works.
on the upload side it should just put it into your web directory if you don't include a file path, you might have to do some directory changes, can't remeber to long since made ftp class.
I have the .php file and somefile.txt in the same directory. Even so, I tried the full path and still no luck. Maybe I have the wrong syntax in place for the root directory.
well, i'll tell you what the most likely problem is. you aren't setting the directory into which FTP will look to upload files from. ie, it's probably looking in the default directory for somefile.txt (ie, c:\windows\desktop\). i would set the default directory to be wherever you are trying to upload from, as well as set the directory into which you are trying to upload TO as you may be trying to upload to the root directory without the correct privelages.
if all else fails, change your error messages from FTP Upload failed 1 for the first fail, FTP Upload Failed 2! for the second error and so on to pinpoint just where exactly your problem exists...
I changed the source directory to exactly where the file is. I also changed the destination directory to where I want the file. Maybe the syntax '.../...somefile.txt' is incorrect?
I am trying to upload a file from my hard drive to a server, that's the point of an FTP program after all. It's just as simple as using an FTP program (say in Dreamweaver) that takes a file saved on one's hard drive and places it on a server. There has to be a way to do this...
The following uploads an image from local hard drive to the server. The $_SESSION var is the server subdirectore assigned to the logged in user, so just replace it with your desired server folder name.
I appreciate the code you have posted, but that is not what I want to do. I want to do what I previously mentioned. No user is logged onto the server in my scenario. Also, my files will XML files. Therefore your code would not be appropriate. I just need to know what the syntax is for locating a local file. Thank you.