1

I have this link: http://gdlp01.c-wss.com/gds/6/0300002536/03/PSG11_CUG_EN_03.pdf and I want to copy this file to my FTP server. I tried:

$file = "http://gdlp01.c-wss.com/gds/6/0300002536/03/PSG11_CUG_EN_03.pdf"; $data = file_get_contents($url); $ftp_server = "ftp_server"; $ftp_user = "ftp_user"; $ftp_pass = "ftp_pass"; $ftp = ftp_connect($ftp_server,21) or die("Couldn't connect to $ftp_server"); if (ftp_login($ftp, $ftp_user, $ftp_pass)) { echo "Connecté en tant que $ftp_user@$ftp_server\n"; } else { echo "Connexion impossible en tant que $ftp_user\n"; } 

The connection was successful, but after that I do not know how to start.

0

2 Answers 2

1

You'll have to use ftp_fput, but I'm not sure if this function is able to handle an URL (I don't think so), so I decided to put your existing variable into the memory and to fake a file handler:

$tmpFile = fopen('php://memory', 'r+'); fputs($tmpFile, $data); rewind($tmpFile); if (ftp_fput($ftp, 'manual.pdf', $tmpFile, FTP_ASCII)) { echo "worked"; } else { echo "did not work"; } 
Sign up to request clarification or add additional context in comments.

Comments

0

If you have URL wrappers enabled, it's as easy as:

$file = "http://gdlp01.c-wss.com/gds/6/0300002536/03/PSG11_CUG_EN_03.pdf"; $ftp_server = "ftp_server"; $ftp_user = "ftp_user"; $ftp_pass = "ftp_pass"; copy($file, "ftp://$ftp_user:$ftp_pass@$ftp_server/PSG11_CUG_EN_03.pdf"); 

If you need a greater control over the writing (transfer mode, passive mode, offset, reading limit, etc), use the ftp_fput with a handle to the php://temp (or the php://memory) stream.

See Transfer in-memory data to FTP server without using intermediate file.

Comments