Morning Everybody,
I've a problem concerning my code. I'll explain, I've a connexion to a local FTP server on my linux instance. I would like to explore all my directories to unrar my files ".rar" but when I'm launching my script, there is just the display of directories that is working.
I don't know why.
def showDirectories(ftp):
output=' /var/www/folder/Output'
ftp.cwd('/FolderFiles')
ftp.retrlines('LIST')
directories = ftp.nlst()
if directories not in ['..', '.']:
i=0
while i < len(directories):
folder = directories[i]+'/'
i+=1
for root, dirs, files in os.walk(folder, topdown=False):
for name in files:
rarFiles=os.path.join(root, name)
print(rarFiles)
unrar = "unrar x "+rarFiles+output
print("unrar commande"+str(unrar))
download= os.system(unrar)
print(download)
ftp.cwd('..')
print("")
Here the result:
[root@ip-10-0-2-52 folder]# python test.py
Connected! Welcome msg is "220 (vsFTPd 3.0.2)"
Connected !
drwxr-xr-x 2 0 0 90 Feb 11 14:42 DescriptiveData
drwxr-xr-x 2 0 0 75 Feb 11 14:42 Financials
drwxr-xr-x 2 0 0 87 Feb 11 14:42 OwnershipHisto
Thank you for your help
Thank you for you help, finally I've found the solution to make my script work.
Here my updated
def downloadFile(path,target):
for root, dirs, files in os.walk(path, topdown=False):
for name in files:
rarFiles=os.path.join(root, name)
print(rarFiles)
unrar = "unrar x "+rarFiles+target
print("unrar commande"+str(unrar))
download= os.system(unrar)
print(download)
downloadFile('*****','*****')