[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php problem with ftp_put

Posted on 2001-08-18
10
Medium Priority
?
365 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to count occurrences of each item in an array.
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 …
Suggested Courses
Course of the Month19 days, 10 hours left to enroll

873 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