Skip to content

Instantly share code, notes, and snippets.

@IuryAlves
Created June 23, 2013 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IuryAlves/5843444 to your computer and use it in GitHub Desktop.
Save IuryAlves/5843444 to your computer and use it in GitHub Desktop.
# CLI command line interface
# coding: utf-8
# using: python 2.7
import ftpClient as client
commands_list = ['Db', 'Q', 'L', 'Ub', 'H', 'Mv', 'Mk', 'Dl']
ftp = client.connectClient('iury', '42')
print('''
Bem vindo ao cliente FTP\n digite "H" para ajuda e "O" para opcoes ''')
while True:
command = raw_input("entre com um Comando: ")
if command[0] and command[:2] not in commands_list:
print ("Comando invalido")
continue
# exemplo de uso : Db teste.mp3
if command[:2] == 'Db':
try:
arg_find = command.find('-')
first_arg = command[3:arg_find]
second_arg = command[arg_find + 1:]
client.download(ftp, first_arg, second_arg)
except Exception,e:
pass
if command[0] == 'Q':
exit(0)
if command[0] == 'L':
client.listDirectories(ftp)
# example 'Ub musica.py-PastaExemplo/Uploads/musica1.mp3'
if command[0:2] == 'Ub':
try:
arg_find = command.find('-')
first_arg = command[3: arg_find]
second_arg = command[arg_find + 1:]
client.upload(ftp, first_arg, second_arg)
except Exception:
pass
if command[0:2] == 'Mv':
try:
arg = command[command.find(' ')+1: ]
client.moveToDir(ftp,arg )
print(" Agora voce esta no arquivo: " +arg)
except Exception:
pass
if command[0:2] == 'Mk':
try:
arg = command[command.find(' ')+1 : ]
client.makeDir(ftp,arg)
print(" Foi criado o diretorio: ", +arg)
except Exception:
pass
if command[0:2] == 'Dl':
try:
arg = command[command.find(' ')+1 : ]
client.delFile(ftp, arg)
except Exception:
pass
ftp.sendcmd('NOOP')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment