Nell’amministrare un server capita spesso di dover scambiare file via SFTP e se ottimi tool grafici come Transmit possono venire in nostro aiuto spesso è più veloce effettuare qualche operazione da terminale.
Partiamo dal presupposto essenziale, un server con accesso SSH (tramite password o chiave sicura). Una volta verificato di aver accesso con il comando ssh
possiamo procedere come segue:
$ sftp user@server
Al che otterremo un prompt del tipo:
sftp>
Ora potrete ottere una lista dei comandi utili con:
sftp> help Available commands: bye Quit sftp cd path Change remote directory to 'path' chgrp grp path Change group of file 'path' to 'grp' chmod mode path Change permissions of file 'path' to 'mode' chown own path Change owner of file 'path' to 'own' df [-hi] [path] Display statistics for current directory or filesystem containing 'path' exit Quit sftp get [-Ppr] remote [local] Download file help Display this help text lcd path Change local directory to 'path' lls [ls-options [path]] Display local directory listing lmkdir path Create local directory ln oldpath newpath Symlink remote file lpwd Print local working directory ls [-1afhlnrSt] [path] Display remote directory listing lumask umask Set local umask to 'umask' mkdir path Create remote directory progress Toggle display of progress meter put [-Ppr] local [remote] Upload file pwd Display remote working directory quit Quit sftp rename oldpath newpath Rename remote file rm path Delete remote file rmdir path Remove remote directory symlink oldpath newpath Symlink remote file version Show SFTP version !command Execute 'command' in local shell ! Escape to local shell ? Synonym for help
Per spostarsi tra le cartelle è sufficiente conoscere i comandi basilari dei sistemi unix come ls
, cd folder
, pwd
mentre per le operazioni di trasferimento dei file dovrete utilizzare i comandi get
e put
, relativamente per scaricare o caricare file dal e sul vostro server.
Per scaricare o caricare un’intera cartella possiamo procedere con i comandi:
sftp> get -r myDirectory /localFolder/
sftp> put -r myDirectory /remoteFolder/