Como se conectar via PHP á um FTP ou SFTP para o upload ou exclusão de arquivos
No exemplo a seguir utilizamos a biblioteca Net/SFTP: http://phpseclib.sourceforge.net/sftp/examples.html
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('host');
if (!$sftp->login('usuario', 'senha@pM')) {
exit('Login Failed');
}
// puts a three-byte file named filename.remote on the SFTP server
$sftp->put('test.txt', 'test.txt');
// puts an x-byte file named filename.remote on the SFTP server,
// where x is the size of filename.local
//$sftp->put('filename.remote', 'filename.local', NET_SFTP_LOCAL_FILE);
?>
Primeiro parâmetro da função “put” é nome do arquivo no diretório remoto (aonde será feita a conexão) e o segundo é o nome e caminho para o arquivo que será enviado (diretório local)