Solved

php problem with ftp_put

Posted on 2001-08-18
10
323 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
  • 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now