How to transfer file(s) to another server

Hi guys, following code will transfer files into local filesystem of Webserver. It is also possible,tranfering this file to another ftp-server. What about transfering files(s) to another Webserver. Is there any possibility transfering files to another webserver. Actually,I will get error:


failed to open stream: HTTP wrapper does not support writeable connections

That’s way, I upload files to another ftp-server.I am not using any ftp-extension by now







$connection = ftp_connect($server);

$login = ftp_login($connection, $ftp_user_name, $ftp_user_pass);

if (!$connection || !$login) { die('Connection attempt failed!'); }

$upload = ftp_put($connection, $dest, $source, $mode);

if (!$upload) { echo 'FTP upload failed!'; }


Here is code, which 'causes error:

   	if ($model->loadAll(Yii::$app->request->post()) && $model_eingang->loadAll(Yii::$app->request->post())) 

            $model->attachement = UploadedFile::getInstances($model, 'attachement');

            $bez = "E-Mail-Anhang";

            $bez_error = "kein Fehler aufgeteten"

 			$anhangszaehler = 0;

            $anhang = array();

            if ($model->upload()) {

                $folder_read = Yii::getAlias('@uploading/');[

                $folder_write = Yii::getAlias('@emailanhang');

                $upload_copy = opendir($folder_read);

                while ($file = readdir($upload_copy)) {

                    if ($file != "." && $file != ".." && $file != ".gitkeep" && $file != ".gitignore") {

                        copy($folder_read . $file, $folder_write . $file);

                        $folder_http = "";

                        fopen($folder_http.$file,"w"); //this will cause error

                        copy($folder_read . $file, $folder_http . $file);//this will cause error as well

                        $anhang[$anhangszaehler] = $file;







I would recommend you upload the files to you local server and run a background process perhaps even a cron job that moves these files to your remote server won’t recommend you do this in your request process it will kill your application.

Why this. Here is code,which will solve my problem. I don’t understand,why this code could kill my application…



[size=3]                try {

[size=3]     			$model_folder = Dateianhang::find()[/size]

[size=3]                                    ->join('LEFT JOIN', 'e_dateianhang', '')[/size]

[size=3]                                    ->where(['id_mail_ausgang' => $id])->one();                    

				$folder = AppEinstellung::getSpeicherOrt($model_folder);

[size=3]                    $extract_outer = explode("'", $folder);

[size=3]                    $extract_inner = explode(";", $extract_outer[0]);

[size=3]                    $host = $extract_inner[0];

[size=3]                    $username = $extract_inner[1];

[size=3]                    $password = $extract_inner[2];

[size=3]                    $folder_ftp = $extract_inner[3];

[size=3]                    $ftp->connect($host);

[size=3]                    $ftp->login($username, $password);

[size=3]                    $upload_ftp = opendir($folder_read);

[size=3]                    while ($file = readdir($upload_ftp)) {

[size=3]                        if ($file != "." && $file != ".." && $file != ".gitkeep" && $file != ".gitignore") {

[size=3]                            if (preg_match($jpg, $file))

[size=3]                                $mode = FTP_BINARY;

[size=3]                            else

[size=3]                                $mode = FTP_ASCII;

[size=3]                            $ftp->put($folder_ftp . $file, $folder_read . $file, $mode);

[size=3]                        }

[size=3]                    }

[size=3]                    closedir($upload_ftp);

[size=3]                } catch (\Exception $error) {

[size=3]                    $session->addFlash("info", "Die Konfigurationsparameter Ihres FTP-Servers sind inkorrekt.Die E-Mail wurde folglich nicht versandt.Bitte informieren Sie Ihren Admin!");

[size=3]                    return $this->redirect(['index']);