Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

problems with ftp_put method for uploading to ftp server

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

problems with ftp_put method for uploading to ftp server

Postby outsorts » Fri Feb 21, 2014 3:51 am

i'm having a problem in uploading a file from my local computer to my ftp server where when using a code as simple as this:

Code: Select all
<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

$file = "localfile.txt";

// upload file
if (ftp_put($ftp_conn, "serverfile.txt", $file, FTP_ASCII))
  {
  echo "Successfully uploaded $file.";
  }
else
  {
  echo "Error uploading $file.";
  }

// close connection
ftp_close($ftp_conn);
?>


except of coarse with entering my own server info, i get the echo "Error uploading $file." and the only way it works is when i make the local file and the remote file having the same name, and even at this case the remote file is being overwritten by zero byte file size in my ftp server which is actually useless.
any help for this issue?
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am

Re: problems with ftp_put method for uploading to ftp server

Postby outsorts » Fri Feb 21, 2014 4:02 am

correction after retesting the problem is the local file gets uploaded even if change the names and i get the echo that it was uploaded but it's size is zero.
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am

Re: problems with ftp_put method for uploading to ftp server

Postby outsorts » Fri Feb 21, 2014 4:35 am

also i turned on passive mode and i have the same problem.
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.