moomsdad Posted March 29, 2008 Share Posted March 29, 2008 Hello, I have been trying to find the definitive script for using PHP in a form on an html page that will upload (using SFTP) a large file to a remote location... I have found some help, and had some limited success using ftp, but need to use SFTP. Most comments I find all talk about the differences between SFTP and FTP, but most are from more then a year ago, and I can't find a clear answer... To add complications to it, I am new to programming (I know you hate these kinds of questions I am sure)... Is there an easy way to send a large file to a remote location using SFTP with PHP or for that matter, any other scripting method? Sorry to be a bother, and thanks in advance for your advice... Quote Link to comment https://forums.phpfreaks.com/topic/98469-sftp-ftp-with-php/ Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 are you asking for FTP over SSH is sometimes referred to as secure FTP or securing FTP, such as with SSL/TLS (FTPS). *UNTESTED <?php $ftp_server = "xxx.xxx.xxx.xxx"; $ftp_port = 21; $ftp_timout = 90; $ftp_user_name = "root"; $ftp_user_pass = "secureFTP"; $remote_file = "helloworld.txt"; $file = "helloworld.txt"; // set up basic ssl connection $conn_id = ftp_ssl_connect($ftp_server, $ftp_port, $ftp_timout); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); //Returns the current directory name echo ftp_pwd($conn_id); // upload a $file to $remote_file (includeing the name) if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) { echo "successfully uploaded $file\n"; } else { echo "There was a problem while uploading $file\n"; } // close the ssl connection ftp_close($conn_id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98469-sftp-ftp-with-php/#findComment-504038 Share on other sites More sharing options...
moomsdad Posted March 29, 2008 Author Share Posted March 29, 2008 Sorry Not sure... I was told the only way to connect to the server where I need to have people upload their contest submissions, was with a MAC using AFP or with a PC using SFTP (The server is MAC based "xserver")... I have tried many different FTP programs, and had only some success on PC. I thought if I could find a script to do it all in the background, we would not have to let each of the people submitting entries, to have to download an FTP program that may or may not work... The code you have posted looks similar to what I have been playing with for a couple of days, with a couple of changes, so I guess I will try it... Thanks again for your insight, Quote Link to comment https://forums.phpfreaks.com/topic/98469-sftp-ftp-with-php/#findComment-504075 Share on other sites More sharing options...
MadTechie Posted March 29, 2008 Share Posted March 29, 2008 if you connecting to a FTP sever on a MAC or PC you can use the standard FTP protocal its not the only way to connect to them, the xserve will probably have OSX installed this will have samba installed this allow PC users to connect to the fileserver so you can have you PHP connect via that as for connecting to via FTP i would suggest checking the PC & Mac servers FTP setup by installing a client and connecting to them and uploading a file or two, once your sure the servers FTP setup is correct then create a simple FTP script in PHP <?php $ftp_server = "xxx.xxx.xxx.xxx"; $ftp_user_name = "user"; $ftp_user_pass = "pass"; $destination_file = "file.txt"; $source_file = "file.txt"; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name"; } // upload the file $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); // check upload status if (!$upload) { echo "FTP upload has failed!"; } else { echo "Uploaded $source_file to $ftp_server as $destination_file"; } // close the FTP stream ftp_close($conn_id); ?> Quote Link to comment https://forums.phpfreaks.com/topic/98469-sftp-ftp-with-php/#findComment-504084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.