Copying files from local directory to remote server
Posted: Fri Apr 08, 2016 5:15 am
How do I copy the pdf and csv files in the local folder to a folder in remote server using symfony?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Yes, you would use some program on your system to do that. Are the source and target servers Linux or Windows?sobha wrote:using symfony?
Code: Select all
public function uploadFile($local_file, $remote_file)
{
$sftp = $this->sftp;
$stream = @fopen("ssh2.sftp://$sftp$remote_file", 'w');
if (! $stream)
throw new \Exception("Could not open file: $remote_file");
$data_to_send = @file_get_contents($local_file);
//$contents = stream_get_contents($stream);
if ($data_to_send === false)
throw new \Exception("Could not open local file: $local_file.");
if (@fwrite($stream, $data_to_send) === false)
throw new \Exception("Could not send data from file: $local_file.");
@fclose($stream);
return $data_to_send;
}