ftp_put() problems

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, I am having problems with the ftp_put() function. I can login
via shell prompt.

Does anyone know why the ftp_put() function may not work? I went to the
php site and followed the directions. I am connecting because I am not
getting an error. I am also logging in with the username and password
because I am not getting an error here as well. But so far no matter
what I do, the file will not upload.

Any help with this would be great.

$query    = "select Server, UserName, Password, Destination_Path,
ServerType from company";

$result    = @mysql_query($query);

$row    = @mysql_fetch_array($result);

if (!empty($row["Server"]))
$hostip = gethostbyname($row["Server"]);
$conn_id = ftp_connect($hostip);

// set up basic connection
//$conn_id = ftp_connect($row["Server"]);

// login with username and password
$login_result = ftp_login($conn_id, $row["UserName"],

// check connection
if ((!$conn_id) || (!$login_result))
$value = "FTP connection has failed!<br>
Attempted to connect to ".$row["Server"]." for user ".$row["UserName"];

// IMPORTANT!!! turn passive mode on
//tried this and it did not help
//ftp_pasv ( $conn_id, true );

//parameters are ftp_put($conn_id, $destination_file, $source_file,

$upload = ftp_put($conn_id, $row["Destination_Path"]."/".
'])),  strtolower(trim($HTTP_POST_FILES['userfile']['name
'])), FTP_BINARY);

if (!$upload)
echo $upload."<br><br>Did not upload to ftp server.";

// close the FTP stream

I am not getting any errors and the file is not getting uploaded.

-my server var holds the URl of the server ex. 'test.com'

- my destination file var holds the path temp

so the destination path when I echo it is temp/my file

so the ftp_put() is getting passed

ftp_put($conn_id, 'temp/myfile', 'myfile', ftp_binary);

This is the first time I have ever used this function so please bear
with me. I have researched it and no one seems to have this problem.
Most people complain that the file seems to get uploaded but its file
size is 0. Right now, my page runs and nothing happens. My permissions
on the server are correct, the folder I am trying to upload to exists,
the username and pass are correct and I can login via shell prompt as

Any ideas?

Re: ftp_put() problems

Quoted text here. Click to load it

Make sure the destination path is a single filename... no folders, if it  
is in a different folder change directory's to that folder.

Next make sure that your source file has the full path otherwise how is  
it going to know what file to send?

also claiming binary is a good thing but this script looks like it  
directly takes a users input and places it on the server... so what  
happens when you get a text file... if this is user input you should  
really screen out some files and check for viruses against that file.

Thats about it.


Re: ftp_put() problems

Thank you for the reply. I will try what you suggested. One thing I am
curious about is why would I need the full path to the source file?

For example, why do I not have to pass in the full path when just
uploading a file like this:

$path."/".$HTTP_POST_FILES['userfile']['name']) I do not give it the
full path, just the tmp name of the file. I thought that having access
to the post file[userfile][name] would be enough.

Thanks again for your time

Re: ftp_put() problems

Another thing I am confused about (forgive my lack of knowledge here)
but I do not see how to change directories from the site server. For
example if I call

// current directory
echo getcwd();

I will get the CWD of the current file I am in on the website, not the
current folder I am trying to ftp into remotely. If I call
chdir('public_html/temp') this is not on the sever the website you are
currently uploading from.

So I do not understand how to chg dirs on a remote server that you are
trying to ftp to using php and it not look at the server you are
currently sitting on.

Can you please clarify because I am really confused.


Re: ftp_put() problems

I have tried uploading directly to the root folder and it still does
not work. Can maybe someone show me a example of the proper way to use
this function? I have looked at a few examples and I thought I had my
code laid out like the examples. I have also check file/folder
permissions and this is not an issue.

Thanks again

Site Timeline