#change directory:
cd
lcd
 
#list directory contents:
ls
!ls
 
#print local working directory:
pwd
lpwd
 
#Put a file:
put filename
 
#Put multiple files:
mput filename1 filename2
 
#Get a file:
get filename
 
#Get multiple files:
mget filename1 filename2
 
# To login to a host with sftp:
lftp -u $username sftp://$host

lftp

recursively download a directory

mirror $directory

upload recursively:

mirror --reverse $directory

put file

upload di un singolo file

lftp -"open ftp://$username:$password@$host; lcd $lcd; cd $rcd; put all.min.css";

upload script: attenzione al flag **--reverse: upload your remote folder**

#!/bin/bash
host='test.com'
user='test'
passwd='test'
lcd='/home/test/backups'
rcd='/new'
 
lftp -f "
open $host
user $user $passwd
lcd $lcd
mirror --reverse --delete --verbose $lcd $rcd
bye
"

download remote folder to local

# metodo 1
lftp -" open ftp://$user:$pass@$host; lcd $lcd; cd $rcd; mirror  --no-perms  --continue --verbose  --parallel=2 --only-missing  --only-newer --no-recursion --no-perms "

# metodo 2
lftp -"
open 
$HOST
user 
$USER $PASS
lcd 
$lcd
mirror --delete --verbose 
$lcd $rcd
bye
"

upload cartella

<?php
function action_sync_test() {
    
$username '';
    
$password '';
    
$host     '192.168.0.0';
    
$lcd      realpath(__DIR__.'/..');
    
$rcd      '/the/path';
    return 
ftp_sync_dir($username$password$host$lcd$rcd);
}

function 
ftp_upload_dir($username$password$host$lcd$rcd){
    
// --delete elimina ogni file non presente
    // --only-newer carica solo i files più recenti sul path locale
    $cmd_options ' --reverse --delete  --no-perms  --continue --verbose  --parallel=2 ';

    
// aggiunge opzione dryrun ammeno che non si dia il comando --go
    $cmd_options .= init_dry_run();

    
// serve a sovrascrivere files nascosti come .htaccess
    // set ftp:list-options -a;
    $cmd "lftp -c \" open ftp://$username:$password@$host; lcd $lcd; cd $rcd; mirror $cmd_options\"";
    echo 
$cmd."\n";
    echo `
$cmd`;
}

function 
ftp_download_dir($username$password$host$lcd$rcd){
    
// --delete elimina ogni file non presente
    // --only-newer carica solo i files più recenti sul path locale
    $cmd_options ' --no-perms  --continue --verbose  --parallel=2 --only-missing  --only-newer --no-recursion --no-perms ';

    
$cmd "lftp -c \" open ftp://$username:$password@$host; lcd $lcd; cd $rcd; mirror $cmd_options\"";

    echo 
$cmd."\n";
    echo `
$cmd`;
}

install sever

  • vsftpd: If you want to run a FTP server at scale with many users, ubuntu default
  • ProFTPd: If you want a server with the most flexible configuration options and external modules linux_proftpd
  • PureFTPd: If you have just a few users and want a simple, secure FTP server