Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Uploading files via ftp

General discussions related to php

Moderators: macek, egami, gesf

Uploading files via ftp

Postby outsorts » Sat Apr 26, 2014 7:11 am

I not very experienced about the client and server things, so my question may seem a little simple but important.
I was trying to use my local PC as a server for uploading files to a my remote server then downloading those files later from any where.

So i used a php code to do this using ftp_put method , but the problem is whenever i upload a file i find it with zero byte on the remote server and for saving your time, it does not have something to do with file permissions or turning on passive mode or any other bug in my code because i have contacted my self the host providers and gave them my code and they said it worked perfectly on their side.

So what am i missing.

Do i need a program such as Wamp or File zilla server when ftp uploading a file by php to have the operation successfully done?
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am

Re: Uploading files via ftp

Postby seandisanti » Sat Apr 26, 2014 7:44 am

If it works perfectly on a different computer but not on yours, then the solution lies in the differences between the two computers executing it. Noone can make any kind of a guess as to what you're doing wrong without seeing what you're doing. Show some code (with your credentials redacted from it) and you'll get help fairly quickly
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Uploading files via ftp

Postby outsorts » Sat Apr 26, 2014 8:18 am

ok here is my code:
Code: Select all
<?php
// connect and login to FTP server
$ftp_server = "";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
   $login = ftp_login($ftp_conn,"","") or die("invalid username or password");

//$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);

// turn passive mode on
ftp_pasv($ftp_conn, true);
    //ftp_chdir($ftp_conn, "/htdocs/uploads/") or die("could not find dir");
    ftp_chdir($ftp_conn, "/public_html/") or die("could not find dir");

 
$file ="z.png";
$source_file="z.png";
$destination_file="test.png";

if (ftp_put($ftp_conn, $destination_file, $source_file, FTP_BINARY))

  {
  echo "Successfully uploaded $source_file.";
  }
else
  {
  echo "Error uploading $source_file.";
  }

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


Of coarse i have not written my ftp account information here for privacy.

But still i didn't have an answer to my question where it was related to use software such as File zilla server or WAMP or not.
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am

Re: Uploading files via ftp

Postby seandisanti » Sat Apr 26, 2014 8:55 am

about to look at your code, but the other questions: filezilla is a client side ftp program, unless you're trying to automate its implementation (which you're not, i promise) it would not be relevant here. wamp is an application stack that runs the necessary servers to host a page on your local machine. If you're using wamp to test code, then you could very well be having issues because of permissions etc on your local machine vs the server you actually intend the code to run on. Those differences range from permissions, to version discrepancies. use phpinfo() on your dev and production servers to make sure you're using the same version etc. And now i'm going to look at your code
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Uploading files via ftp

Postby seandisanti » Sat Apr 26, 2014 9:10 am

Code looks pretty standard, i'd say to verify permissions on the folders you're uploading to, on your wamp server and on the real server.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Uploading files via ftp

Postby outsorts » Sat Apr 26, 2014 11:09 am

I said from the first place it was not a permission issue since i all permissions are set to do everything on the remote server and on the local server.
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am

Re: Uploading files via ftp

Postby seandisanti » Sat Apr 26, 2014 11:53 am

I know what you said, but you then followed it up with stupid questions. The code looks good, and by your own account works on a different server; you didn't respond with the results of comparing phpinfo() on the servers, so the only conclusion to logically be drawn is that you may have been mistaken in your assertion that it's not a permission issue. Perhaps you are making incorrect assumptions about the permissions on a file after it is uploaded, like the one you are apparently making about people being required to donate their time to help you.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Uploading files via ftp

Postby outsorts » Sat Apr 26, 2014 1:50 pm

man you couldn't answer the question , just admit it or say nothing , you don't have to use appropriate language....by the way i have reported it you.
outsorts
New php-forum User
New php-forum User
 
Posts: 7
Joined: Fri Feb 21, 2014 3:44 am

Re: Uploading files via ftp

Postby seandisanti » Sat Apr 26, 2014 5:17 pm

Actually I went out of my way to help, and didn't use any inappropriate language even after you went out of your way to prove yourself ungrateful and undeserving of assistance, so let me know how that report works out for you. On the bright side, my projects all work. :D


***edit***
fixed a typo
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP 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.