Copying files from local directory to remote server
Moderator: General Moderators
Copying files from local directory to remote server
How do I copy the pdf and csv files in the local folder to a folder in remote server using symfony?
Re: Copying files from local directory to remote server
You can't copy files across servers. You'll have to use something like FTP or an SSH tunnel, and what you do depends on what the remote server supports...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Copying files from local directory to remote server
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?
(#10850)
Re: Copying files from local directory to remote server
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;
}- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Copying files from local directory to remote server
I assume that $data_to_send actually contains data? And that fwrite() is returning the number of bytes written? Maybe don't suppress errors to see what is going wrong?
(#10850)