Solved

FTP upload error

Posted on 2007-04-10
9
524 Views
Last Modified: 2013-12-13
I am trying to make ftp uploadform.  We have runninf ftpserver which located different server than php. There is a directory named 'incoming'. Those upload files have to go on that directory.
Here is my error message:
Connected to ftp.studio.fi, for user asiakas
Warning: ftp_put() [function.ftp-put]: Access denied. in c:\inetpub\wwwroot\upload.php on line 31
FTP upload of login_05.jpg has failed!

And here is 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 = "ftp.studio.fi";      // FTP Server Address (exlucde ftp://)
    $ftp_user_name = "asiakas";     // FTP Server Username
    $ftp_user_pass = "studio";      // 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);
             // turn passive mode on
    ftp_pasv($conn_id, true);
    // 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_file, FTP_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">
            Valitse tiedosto: <input name="txt_file" type="file" size="35" />
            <input type="submit" name="start_upload" value="Upload File" onClick="dispProgress()" />
        </form>

Here is info about php.ini file
- FTP support  enabled
- upload_tmp_dir C:\PHP\uploadtemp  
0
Comment
Question by:tikkanen
  • 3
  • 3
  • 3
9 Comments
 
LVL 19

Expert Comment

by:v2Media
Comment Utility
FTP on windows via php is a bit fiddly. First, you need a fully functional FTP system. Once FTP is working correctly, then you know PHP or permissions are to blame. In you case, I'd say permissions.

Check out this article on setting up FTP on win2k3; much of it will apply to an XP box as well...

http://www.windowsnetworking.com/articles_tutorials/Creating-Configuring-FTP.html
0
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
Shouldn' this line:
$destination_file = "/".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)
be more like
$destination_file = "./".basename($_FILES['txt_file']['name']);  // Path for File Upload (relative to your login dir)
so it matches the comment?
0
 

Author Comment

by:tikkanen
Comment Utility
Correction, we have ftp server (war daemon manager) same server as php. Our customer can upload files with ftp-program. When they tranfers files they have to be  on passive mode or 'passive transfer'.
All files have to go ingoming directory.
ftp://ftp.printstudio.fi/

I change lines "./" and i get next error message:

Connected to ftp.printstudio.fi, for user asiakas
Warning: ftp_put() [function.ftp-put]: Access denied. in c:\inetpub\wwwroot\upload.php on line 32
Line 32 is this:     $upload = ftp_put($conn_id, $destination_file, $local_file, FTP_BINARY);  // Upload the File
0
 
LVL 19

Expert Comment

by:v2Media
Comment Utility
IUSR_COMPUTERNAME needs to have write permissions to the directory.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 19

Accepted Solution

by:
v2Media earned 250 total points
Comment Utility
I strongly suggest reading the article I posted above to ensure your ftp server is configured with some kind of security, otherwise you're opening yourself up to warez crews discovering free ftp space to mirror their files.
0
 
LVL 48

Expert Comment

by:hernst42
Comment Utility
Maybe the settings of your ftp-server does not allow a user from localhost to upload files, even if he is allowed to upload from an external ip? The problem is the configuration of your ftp-server. Check the logs there
0
 

Author Comment

by:tikkanen
Comment Utility
Is it more secure and clear to make an upload form where user can upload stuff on php server. Not ftp server? Any suuggestion?
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 250 total points
Comment Utility
upload via form and php-verification is more secure than giving anyone write access to a ftp-server. Ifyou store the uploaded files in a ftp-server or on the webserver does not really matter.
0
 

Author Comment

by:tikkanen
Comment Utility
Ok, I will try that. Thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

17 Experts available now in Live!

Get 1:1 Help Now