Upload via php ftp

software development


I’m trying to upload a directory from my computer via a PHP script I’m writing. It isn’t working and I can’t figure out why.

First of all, connecting to the FTP server. For ftp_connect($ftp_server), what do I set $ftp_server to?
ftp.mysite.com, webServerName.dreamhost.com or something else?

Getting this right might fix my other problems, so I’ll wait to post them.



ftp.mysite.com should work.


Thats what I thought. Now onto my next problem I have…
I’m trying to upload an entire directory from my computer to my web server using ftp_put(). Lets say the directory I want to upload is C:/files/upload/. I want to move “upload” and all of the files/folders in it to “mysite.com/etc/” So the final product would be “mysite.com/etc/upload/”. Here’s what I have, which isn’t working:

ftp_put($conn_id, $dst, $src, FTP_BINARY);

The error I get says, “Warning: ftp_put(C:/files/upload/)Failed to open stream: No such file or directory in C:\path\of\script\ftp.php” even thought I’m sure the $src directory exists.

BTW, I’m running this php script on localhost using WampServer.


ftp_put uploads files only.

If you want to upload a directory, you will need some scripts to retrieve all the file names in the directory and upload one by one.

You can write your own scripts to do that, or use open source scripts like phpftp

An easy way is to use DH webftp tool via DH panel --> Domains --> Manage Domains --> WebFTP. It allows you to upload files, directories, or zip files.

Note: the max upload limit of PHP in DH is 7MB. If you want to change that, you have to compile your own php.ini file.

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


Thanks pat. Unfortunately, I cannot use webftp for what I’m doing. I found a script on php.net for uploading entire directories. I’ll give that a try.