/**
$pathFile /folder/somefile.txt
$ftpHost ftp://ftp.blablabla.com/path/to/upload/
$ftpUser someuser
$ftpPass somepass
**/
function ftpUpload($pathFile, $ftpHost, $ftpUser, $ftpPass){
try {
$parse_url = parse_url($ftpHost);
$ftp_connect = @ftp_connect(@$parse_url['host']);
if(!$ftp_connect){
throw new Exception('1-Falha ao conectar');
}
$ftp_login = @ftp_login($ftp_connect, $ftpUser, $ftpPass);
if(!$ftp_login){
throw new Exception('2-Falha ao conectar');
}
$ftp_chdir = @ftp_chdir($ftp_connect, @$parse_url['path']);
if(!$ftp_chdir){
throw new Exception('3-Falha ao alterar pasta');
}
$ftp_put = @ftp_put($ftp_connect, basename($pathFile), $pathFile, FTP_ASCII);
if(!$ftp_put){
throw new Exception('4-Falha na transmissão do arquivo');
}
}
catch ( Exception $ex ){
throw new Exception($ex->getMessage());
}
}
$pathFile /folder/somefile.txt
$ftpHost ftp://ftp.blablabla.com/path/to/upload/
$ftpUser someuser
$ftpPass somepass
**/
function ftpUpload($pathFile, $ftpHost, $ftpUser, $ftpPass){
try {
$parse_url = parse_url($ftpHost);
$ftp_connect = @ftp_connect(@$parse_url['host']);
if(!$ftp_connect){
throw new Exception('1-Falha ao conectar');
}
$ftp_login = @ftp_login($ftp_connect, $ftpUser, $ftpPass);
if(!$ftp_login){
throw new Exception('2-Falha ao conectar');
}
$ftp_chdir = @ftp_chdir($ftp_connect, @$parse_url['path']);
if(!$ftp_chdir){
throw new Exception('3-Falha ao alterar pasta');
}
$ftp_put = @ftp_put($ftp_connect, basename($pathFile), $pathFile, FTP_ASCII);
if(!$ftp_put){
throw new Exception('4-Falha na transmissão do arquivo');
}
}
catch ( Exception $ex ){
throw new Exception($ex->getMessage());
}
}
Nenhum comentário:
Postar um comentário