大家早上好
我的代码有问题。我将说明,我与Linux实例上的本地FTP服务器有关。我想浏览我所有的目录以解压缩我的文件“ .rar”,但是当我启动脚本时,仅显示正在运行的目录。
我不知道为什么。
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("")
结果在这里:
[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
谢谢您的帮助
答案 0 :(得分:0)
谢谢您的帮助,终于找到了使我的脚本正常工作的解决方案。
这里是我的更新
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('*****','*****')