Solved

php problem with ftp_put

Posted on 2001-08-18
10
346 Views
Last Modified: 2011-09-20
I have a problem with php4's ftp_put


I'm trying to send a file to a remote server, It opens the connection ok, creates an empty file then fails.

It gives an error message
Warning: ftp_put: PORT command successful. in liveStats.php3 on line 228

But it isn't successful - it just creates an empty file.

I can ftp to this site using other ftp software and have used this same bit of code to ftp to the site before.


Any ideas?


The code is

     // set up basic connection
     $conn_id = ftp_connect($address);

     // login with username and password
     $login_result = ftp_login($conn_id, $username, $pwd);

     // check connection
     if ((!$conn_id) || (!$login_result)) {
               $str.= "Ftp connection has failed!";
               $str.= "Attempted to connect to $ftp_server";
               die;
          } else {
               $str.= "Connected<br>";
          }

     // upload the file (dest,source)
     $upload = ftp_put($conn_id, $path.$source_file, $source_file, FTP_ASCII);

     // check upload status
     if (!$upload) {
               $str.= "Ftp upload has failed!";
          } else {
               $str.= "Uploaded ".$source_file." <br>\n";
          }

     // close the FTP stream
     ftp_quit($conn_id);

return $str;

0
Comment
Question by:Nick1181
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 6400667
What kind of file are you uploading?

Have you tried using FTP_BINARY instead of FTP_ASCII?

:o)

Ant
0
 

Author Comment

by:Nick1181
ID: 6400685
Just a little text file. test.txt

I've tried using both FTP_BINARY and FTP_ASCII
0
 

Author Comment

by:Nick1181
ID: 6400718
It doesn't seem to want to send to another server I tried as well - probably doesn't want to send to any server
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 15

Accepted Solution

by:
a.marsh earned 200 total points
ID: 6400722
What operating system(s) are you using?

Ant
0
 

Author Comment

by:Nick1181
ID: 6400733
It doesn't seem to want to send to another server I tried as well - probably doesn't want to send to any server
0
 

Author Comment

by:Nick1181
ID: 6400749
Linux
Apache/1.3.14
PHP Version 4.0.5

http://www.the-afs.com/test.php3 for phpinfo()

0
 

Author Comment

by:Nick1181
ID: 6400844
Well I got it to go though I'm utterly mystefied as to why.

I just copied and pasted an example verbatim - then adapted it. As far as I can see the only difference is that

$upload = ftp_put($conn_id, $dest_file, $source_file, FTP_BINARY);

doesn't work and

$upload = ftp_put($conn_id, "$destination_file", "$source_file", FTP_BINARY);

does. ie: it seems to want quotes around the variable names - which is a whisker on the obscure side. Still, there you go


Thanks

Nick
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6400851
You say that this code has worked before...was that on a different machine and/or a different version of PHP?

There are bugs listed for these functions but they are generally when using Windows, not Linux.

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6400857
Okay - glad you sorted it.

However I'm not so pleased that you gave me a grade C.

If my help really wasn't worth more than that then I would rather that you deleted the question.

:o\

Ant
0
 

Author Comment

by:Nick1181
ID: 6401047
Sorry, As you can possibly spot from my duplicate reply I'm not exactly up to speed with this system.

I appreciate your help believe me. As it was the things you suggested weren't solutions so what do I do? Give you an A for something that wasn't a solution? Just deleting the question seemed a little rude - If giving a C is ruder then I guess I'll just delete in future.

Sorry again


Nick
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question