jomla Posted November 6, 2016 Share Posted November 6, 2016 Hi at all When I make a nysql backup I memorize the files to a remote backup folder and only after I transfer them with FileZilla to my local PC.It is a long way therefore To send local files automatically I tryed a script that compresses my gz files and send the zip file to me, but after I must unzip it to an appropriate folder and it is always a long way .Therefore I am looking for a ftp script that works well.NOW I'm testing follow script but works well only until the login.but ftp_get function does not work, perhaps why the path of the local or remote file are wrong??? This is my ftp script <?php $local_file = 'C:\Users\bull\Documents\web site\town\backups'; $server_file = '/home/markus/public_html/backups'; $ftp_user="markus"; $ftp_pass="aaaaaaaaaaa"; $ftp_server="server.net.net"; // set up a connection or die $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); // try to login if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) { echo "Connected as $ftp_user@$ftp_server<br> successfully"; } else { echo " connect falled as $ftp_user\n"; } //IT work very well still here only But the follow ftp_get function make error if (ftp_get($conn_id, $local_file, $server_file, FTP_ASCII)) { echo " amd Successfully written to $local_file\n"; } else { echo " but There was a problem in download<br>$conn_id<br>$local_file<br>$server_file"; } // close the connection ftp_close($conn_id); ?> IF error is remote and/or local folder name how can I do to discover right folder name because I tryed many name still now and all falled Program not display any warning Link to comment Share on other sites More sharing options...
justsomeguy Posted November 7, 2016 Share Posted November 7, 2016 ftp_get expects a file, not a directory. There is a function in the comments in the documentation to list the files in a directory and download each one. http://php.net/manual/en/function.ftp-get.php Link to comment Share on other sites More sharing options...
jomla Posted November 10, 2016 Author Share Posted November 10, 2016 ftp_get expects a file, not a directory. There is a function in the comments in the documentation to list the files in a directory and download each one. http://php.net/manual/en/function.ftp-get.php Ok thankyou. Follow I report the new stram of my new php code that try to download files but that do not work still now: $local_dir = "C:/Users/markus/Documents/web sites/lands/backups"; $server_dir="/public_html/backups"; $contents = ftp_nlist($conn_id, $server_dir);//works fine still here foreach ($contents as $file) { if (ftp_get($conn_id, $local_dir."/".$file, $server_dir."/".$file, FTP_ASCII)) { echo " amd Successfully written to $local_file\n"; } else { echo " but There was a problem in download<br>".$server_dir."/".$file."<br>"; } } // please where is problem? is there in $local_dir name or $server_dir name? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 10, 2016 Share Posted November 10, 2016 What does it print? What happens when you run that? Link to comment Share on other sites More sharing options...
jomla Posted November 10, 2016 Author Share Posted November 10, 2016 What does it print? What happens when you run that? [10-Nov-2016 11:20:10 Europe/Berlin] PHP Warning: ftp_get(): Filename cannot be empty in /public_html/backup.php on line 28 [10-Nov-2016 11:20:10 Europe/Berlin] PHP Warning: ftp_get(): Error opening in public_html/backup.php on line 28 [10-Nov-2016 11:24:00 Europe/Berlin] PHP Warning: ftp_get(C:/Users/markus/Documents/web site/lands/backups//.): failed to open stream: No such file or directory in /public_html/backup.php on line 26 [10-Nov-2016 11:24:00 Europe/Berlin] Link to comment Share on other sites More sharing options...
justsomeguy Posted November 10, 2016 Share Posted November 10, 2016 It sounds like you need to check the items that you're telling it to download. It looks like you're trying to tell it to download the file "/.", which is the current directory. You need to check each item that ftp_nlist returned to see if it's a file or directory. It looks like that function in the comments in the manual uses the trick of trying to change to the directory. If that works, then it's a directory, otherwise it's a file. For some reason there isn't just a function to check if an FTP entry is a directory, but that might be a limitation of FTP. Link to comment Share on other sites More sharing options...
jomla Posted November 13, 2016 Author Share Posted November 13, 2016 It sounds like you need to check the items that you're telling it to download. It looks like you're trying to tell it to download the file "/.", which is the current directory. You need to check each item that ftp_nlist returned to see if it's a file or directory. It looks like that function in the comments in the manual uses the trick of trying to change to the directory. If that works, then it's a directory, otherwise it's a file. For some reason there isn't just a function to check if an FTP entry is a directory, but that might be a limitation of FTP. Now error is this: Warning: ftp_get(C:/Users/Markus/Documents/web_sites/lands/backups/lands-20161105-1747.gz): failed to open stream: No such file or directory in /home/xyz/public_html/backups.php on line 38 Link to comment Share on other sites More sharing options...
justsomeguy Posted November 14, 2016 Share Posted November 14, 2016 It says the file doesn't exist. Link to comment Share on other sites More sharing options...
jomla Posted November 15, 2016 Author Share Posted November 15, 2016 It says the file doesn't exist. Instead it exist end path is right Link to comment Share on other sites More sharing options...
justsomeguy Posted November 15, 2016 Share Posted November 15, 2016 PHP would disagree with you. You've created the destination directory, and the variable holds the name of a file which actually exists on the server? Link to comment Share on other sites More sharing options...
jomla Posted November 17, 2016 Author Share Posted November 17, 2016 the script.php that I use now works well but at the beginning simply moved files from one directory and one of remoro server but not brought me the file locally. The mistake was that the script should be installed in a local server and not on a remote server. Now that I've installed the script in HTDOCS directory in my local XAMPP server the script works well but takes the files in the htdocs directory in the midst of the scripts .. In practice it is useless ahahahah So much work for nothing the script I use now works well at the beginning but simply moving files from one directory and one of remoro server but not brought me the file locally. The mistake was that the script should be installed in a local server and not on a remote server. Now that I've installed the script in HTDOCS directory in my local XAMPP server the script works well but takes the files in the htdocs directory in the midst of the script .. In practice it is useless ahahahah So much work for nothing Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2016 Share Posted November 17, 2016 PHP code only executes on the server that runs it. If you were running that script on a remote server and expecting files to be downloaded to your local computer, that doesn't work because the remote server doesn't know what the C: drive is, it doesn't have one. There's no connection between your computer and the server, that's what FTP is for, to make that connection. That means that either you need an FTP server installed on your computer that the remote server can connect to and upload files, or you need a web server installed on your local computer to run that code and connect to the remote server. But that code is running on the remote server, when you tell it to copy a file to C: it's looking at its own hard drives, not yours. But, PHP isn't limited to only copying files into the web server's directory structure, you can use it to copy files to any directory as long as the permissions are set up correctly. You can use that to do whatever you want, just tell it the right path to copy the files to and it will do that if the permissions are set up on your hard drive to allow it to do that. Link to comment Share on other sites More sharing options...
jomla Posted November 18, 2016 Author Share Posted November 18, 2016 PHP code only executes on the server that runs it. If you were running that script on a remote server and expecting files to be downloaded to your local computer, that doesn't work because the remote server doesn't know what the C: drive is, it doesn't have one. There's no connection between your computer and the server, that's what FTP is for, to make that connection. That means that either you need an FTP server installed on your computer that the remote server can connect to and upload files, or you need a web server installed on your local computer to run that code and connect to the remote server. But that code is running on the remote server, when you tell it to copy a file to C: it's looking at its own hard drives, not yours. But, PHP isn't limited to only copying files into the web server's directory structure, you can use it to copy files to any directory as long as the permissions are set up correctly. You can use that to do whatever you want, just tell it the right path to copy the files to and it will do that if the permissions are set up on your hard drive to allow it to do that. it was a very informative post Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now