Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 08-08-2007, 06:06 PM
Pc 1203 Pc 1203 is offline
 
Join Date: May 2007
Posts: 88
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default [SOLVED] Remote FTP File Upload

Hi All,
I'm trying to make a image host for my members. Because I just moved hosts, I still have some time left on the "old" one. So, I was thinking I'll use it for the image host uploads. I got this code from php.net an I keep getting this error:


Warning: ftp_login() expects parameter 1 to be resource, boolean given in /home/myusername/public_html/imghost/_upload.php on line 16
FTP connection has failed!
Attempted to connect to myftpserver.com for user imghost@mysite.com

and the source:
PHP Code:
<?php
if(isset($_POST['start_upload']) && $_FILES['txt_file']['name'] != ""){
    
    
$local_file $_FILES['txt_file']['tmp_name']; // Defines Name of Local File to be Uploaded

    
$destination_file "/".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)

    // Global Connection Settings
    
$ftp_server "MyFTPServer.com";      // FTP Server Address (exlucde ftp://)
    
$ftp_user_name "MyUsername";     // FTP Server Username
    
$ftp_user_pass "MySecretPasswordThatIChaged";      // Password

    // Connect to FTP Server
    
$conn_id ftp_connect($ftp_server);
    
// Login to FTP Server
    
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);
   
    
// Verify Log In Status
    
if ((!$conn_id) || (!$login_result)) {
        echo 
"FTP connection has failed! <br />";
        echo 
"Attempted to connect to $ftp_server for user $ftp_user_name";
        exit;
    } else {
        echo 
"Connected to $ftp_server, for user $ftp_user_name <br />";
    }

    
$upload ftp_put($conn_id$destination_file$local_fileFTP_BINARY);  // Upload the File
   
    // Verify Upload Status
    
if (!$upload) {
        echo 
"<h2>FTP upload of ".$_FILES['txt_file']['name']." has failed!</h2><br /><br />";
    } else {
        echo 
"Success!<br />" $_FILES['txt_file']['name'] . " has been uploaded to " $ftp_server $destination_file "!<br /><br />";
    }

    
ftp_close($conn_id); // Close the FTP Connection
}
?>

<html>
    <head>
        <script type="text/javascript">
            window.onload = function() {
                document.getElementById("progress").style.visibility = "hidden";
                document.getElementById("prog_text").style.visibility = "hidden";
            }
           
            function dispProgress() {
                document.getElementById("progress").style.visibility = "visible";
                document.getElementById("prog_text").style.visibility = "visible";
            }
           
        </script>
       
    </head>
    <body>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" enctype="multipart/form-data">
            Please choose a file: <input name="txt_file" type="file" size="35" />
            <input type="submit" name="start_upload" value="Upload File" onClick="dispProgress()" />
        </form>
       
        <img id="progress" src="http://images.mysite.com/progress.gif" />
        <p id="prog_text" style="display:inline;"> Upload Started!</p>
       
    </body>
<html>
Thanks for your help!

- Pc1203
Reply With Quote
  #2  
Old 08-08-2007, 06:21 PM
nico_swd's Avatar
nico_swd nico_swd is offline
 
Join Date: Dec 2005
Location: Spain
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This means that ftp_connect() fails and returns false. Is your port 21? If not, specify another one in the second parameter of ftp_connect(). Does your server maybe have another FTP subdomain such as ftp.your-domain.com ?

Think what else could be the reason that the script cannot connect to your host.

Compare the values you use here with the values of your FTP client which you usually use to transfer your files.
Reply With Quote
  #3  
Old 08-08-2007, 06:22 PM
Pc 1203 Pc 1203 is offline
 
Join Date: May 2007
Posts: 88
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, the FTP is on port 21. The server does not have a FTP subdomain. I'll think of more ways, though.

- Pc1203
Reply With Quote
  #4  
Old 08-08-2007, 06:38 PM
nico_swd's Avatar
nico_swd nico_swd is offline
 
Join Date: Dec 2005
Location: Spain
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you use the same values you're using here, in your FTP client which you usually use to transfer your files... does it work?
Reply With Quote
  #5  
Old 08-08-2007, 06:46 PM
Pc 1203 Pc 1203 is offline
 
Join Date: May 2007
Posts: 88
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just used the same details. The FTP Client worked but the file didn't.

- Pc1203
Reply With Quote
  #6  
Old 08-10-2007, 02:26 AM
Pc 1203 Pc 1203 is offline
 
Join Date: May 2007
Posts: 88
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

BUMP...

- Pc1203
Reply With Quote
  #7  
Old 08-10-2007, 01:46 PM
clark05 clark05 is offline
 
Join Date: Jun 2007
Location: Los Angeles, CA
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use the code from the PHP manual example for ftp_connect so you'll know that the host failed.
PHP Code:
<?php

$ftp_server 
"ftp.example.com";

// set up a connection or die
$conn_id ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

?>
Reply With Quote
  #8  
Old 08-10-2007, 02:08 PM
Pc 1203 Pc 1203 is offline
 
Join Date: May 2007
Posts: 88
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Never mind guys. I just found out the problem. Thanks for your help!

- Pc1203
Reply With Quote
  #9  
Old 08-10-2007, 05:12 PM
nico_swd's Avatar
nico_swd nico_swd is offline
 
Join Date: Dec 2005
Location: Spain
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Mind sharing the solution, in case someone else has the same problem?
Reply With Quote
  #10  
Old 08-10-2007, 06:01 PM
Pc 1203 Pc 1203 is offline
 
Join Date: May 2007
Posts: 88
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Actually, it was a host problem. I didn't check that their FTP was down for an amount of time. My Lesson: Check before you ask

- Pc1203
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:30 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06319 seconds
  • Memory Usage 2,261KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete