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:

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";
    } 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
        <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";
        <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()" />

Here is info about php.ini file
- FTP support  enabled
- upload_tmp_dir C:\PHP\uploadtemp  
Who is Participating?
v2MediaConnect With a Mentor Commented:
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.
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...

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?
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

tikkanenAuthor Commented:
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.

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.
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
tikkanenAuthor Commented:
Is it more secure and clear to make an upload form where user can upload stuff on php server. Not ftp server? Any suuggestion?
hernst42Connect With a Mentor Commented:
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.
tikkanenAuthor Commented:
Ok, I will try that. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.