?
Solved

php problem with ftp_put

Posted on 2001-08-18
10
Medium Priority
?
353 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 15

Accepted Solution

by:
a.marsh earned 400 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
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.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

771 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