Python Forum

Full Version: Python ftp server get the latest sub-directory name
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to write a script to get the latest file from the latest sub- directory of FTP server in python. My problem is i am unable to figure out the latest sub-directory. There are 2 options available, sub-directories have ctime available. Also in directory name date is mentioned that on which date directory was created.But i do not know how to get the name of the latest directory. I have figured out the following way(hoping for the server side to be sorted by latest c time but it is super slow.

import ftplib
import os
import time

ftp = ftplib.FTP('test.rebex.net','demo', 'password')
ftp.cwd(str((ftp.nlst())[0])) #if directory is sorted in descending order by date.

But is there any way where i will find the exact directory by Ctime or by date in directory name ?

Thanks a lot guys
Hello Friends, I am very new to Python.I am trying to write a script to get the latest file from the latest sub- directory of FTP server in python. My problem is i am unable to figure out the latest sub-directory. There are 2 options available, sub-directories have ctime available. Also in directory name date is mentioned that on which date directory was created.But i do not know how to get the name of the latest directory. I have figured out the following way(hoping for the server side to be sorted by latest c time but it is super slow.But is there any way where i will find the exact directory by Ctime or by date in directory name ?

Thanks a lot guys

import ftplib 
 import os
 import time

 ftp = ftplib.FTP('test.rebex.net','demo', 'password')
 ftp.cwd(str((ftp.nlst())[0])) #if directory is sorted in descending order by date