473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

ftp_put() problems

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.

code:
$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"],
$row["Password"]);

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

// 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,
FTP_BINARY)

$upload = ftp_put($conn_id, $row["Destination_Path"]."/".
strtolower(trim($HTTP_POST_FILES['userfile']['name
'])), 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
ftp_close($conn_id);
}
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
well.

Any ideas?
Thanks

Jul 17 '05 #1
5 6713
> $upload = ftp_put($conn_id, $row["Destination_Path"]."/".
strtolower(trim($HTTP_POST_FILES['userfile']['name
'])), strtolower(trim($HTTP_POST_FILES['userfile']['name
'])), FTP_BINARY);

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.

Mike
Jul 17 '05 #2
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:

move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],
$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

Jul 17 '05 #3
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.

Thanks

Jul 17 '05 #4
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

Jul 17 '05 #5
empiresolutions
162 100+
I am haveing the same issue with ftp_put() not working. I have ftp_pasv() on, pathed right. please help
Apr 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joseph Markovich | last post by:
I'm trying to write a script for my users to be able to upload large files, and now I am unsure what exactly I am doing wrong. My script is based on the one in the PHP manual. <?php if(isset(...
1
by: balzano_1 | last post by:
Hi, im trying to upload a file from a client (windows) to an ftp server (linux), i deciede to use some of php`s functions to connect and authenticate etc.. i only wish to put a file on the server,...
2
by: Udo Pecher | last post by:
I apply the following code test.php $upload =ftp_put($conn_id,"test.jpg","$dat",FTP-BINARY); where $dat is a local filename which I like to move via FTP. "test.jpg" ist the filename on the...
1
by: excession | last post by:
I've got a script which uploads a few files to a remote server. The problem is the ftp_put command hands and the script eventually times out. What is even more strange is sometime it works fine. ...
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
5
by: Alex | last post by:
I'm trying to make simple ftp client, used the following article for base: http://www.devarticles.com/c/a/PHP/Building-An-FTP-Client-With-PHP/3/ All works, I can login, see list of files, but...
3
by: empiresolutions | last post by:
ftp_put() is not working. this is what i have. $host = "www.site.com"; $ftp_user_name = "username"; $ftp_user_pass = "password"; // declair files $remote_file = "ITS_BLI_0".$_POST.".csv";...
0
by: sushil | last post by:
Hello Frnds, I am getting problem in uploading file from php script. The error is : Code - $upload = ftp_put($conn_id,$filemax,$src,FTP_BINARY); Output - Resource id...
1
by: PehJota | last post by:
I'm kinda new to PHP, and I'm trying to make a simple FTP upload script. It successfully connects to the server and logs in, but it can't upload. The transfer mode I use normally is ASCII (like I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.