Link to home
Start Free TrialLog in
Avatar of tikkanen
tikkanen

asked on

FTP upload error

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  
Avatar of v2Media
v2Media
Flag of Australia image

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
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?
Avatar of tikkanen
tikkanen

ASKER

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
IUSR_COMPUTERNAME needs to have write permissions to the directory.
ASKER CERTIFIED SOLUTION
Avatar of v2Media
v2Media
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Is it more secure and clear to make an upload form where user can upload stuff on php server. Not ftp server? Any suuggestion?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok, I will try that. Thanks!