473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Having trouble extracting useful directory details from ftplib.FTP


Just recently I decided I want to make use of my ISP freebie webspace.
In order to make that easier, I'd like to be able to automatically
synchronise an FTP file/folder heirarchy with one on my local hard
drive. I figured this should be easily handled in Python, and broadly
speaking it is, but I am having a little difficulty.

You see, in order to handle the synchronise correctly, I need to be
able to determine what is on the FTP server to start with. I need to
be able to recursively search the folders on the FTP server. But so
far as I can tell, I'm having to rely on some very flaky techniques
and some observations about my ISPs FTP server that could potentially
change.

I tried using FTP.nlst(pathname) but this wasn't very helpful...

1. It created a bogus first entry in the list - a line saying
"Found 1" (irrespective of the actual number of items found)
IIRC.

2. It provided no indication of whether each item was a file or
a folder.

Therefore, I switched to using the following piece of code...

filelist=[]
ftp.retrlines ("LIST "+pathname, filelist.append)

I still get a bogus line at the top, but that's easily worked around.
The important thing is that by testing out the results, I found that
for the ftp server I am using I can look at the first character for
the directory flag, and use the slice [53:] to extract the filename
from each line.

The problem is, however, that this seems like skating on very thin
ice. So far as I can tell, there is no standard for the format
reported by the LIST command.

This so far is enough - I can use this to find all files and folders
on the FTP server, and I can download backup copies to a hard drive
folder and then delete them all before uploading the replacement
files, all in one automatic process that (at the moment) just works.
But - apart from the fact that I'm very nervous about it - ideally,
I'd like to do a more sane synchronise - only delete files that need
to be deleted, and only upload files that have changed. To do that, I
need to get more details about the files on the FTP server - time and
date stamps in particular. Getting hold of this information looks like
being at least as much of a hack as what I've done already.

So the question is... Is there some better way of handling this that
I'm missing, or is this just the way it is? After all, there are a lot
of FTP client utilities out there that seem to get this information
perfectly reliably, which seems surprising if they have to rely on
parsing an inconsistent directory listing format.

Any hints?
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #1
2 1852
"Stephen Horne" <st***@ninereeds.fsnet.co.uk> wrote in message
news:et********************************@4ax.com...

Just recently I decided I want to make use of my ISP freebie webspace.
In order to make that easier, I'd like to be able to automatically
synchronise an FTP file/folder heirarchy with one on my local hard
drive. I figured this should be easily handled in Python, and broadly
speaking it is, but I am having a little difficulty.

<snip>
Is this anything like ftpmirror.py? You'll find it in the tools\scripts
directory of the Python distribution.

-- Paul
Jul 18 '05 #2
On Sun, 22 Feb 2004 02:42:59 GMT, "Paul McGuire"
<pt***@austin.stopthespam_rr.com> wrote:
"Stephen Horne" <st***@ninereeds.fsnet.co.uk> wrote in message
news:et********************************@4ax.com.. .

Just recently I decided I want to make use of my ISP freebie webspace.
In order to make that easier, I'd like to be able to automatically
synchronise an FTP file/folder heirarchy with one on my local hard
drive. I figured this should be easily handled in Python, and broadly
speaking it is, but I am having a little difficulty.

<snip>
Is this anything like ftpmirror.py? You'll find it in the tools\scripts
directory of the Python distribution.


Thanks.

It's the exact reverse of what I want (it mirrors from the server to
the local disk, I want to mirror from the disk to the server) but it
is extremely clueful - the way it assumes a standard (unix oriented)
format for the listing unless a Mac server option is specified tells
me precisely what I need to know.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
0
by: Joshua Burvill | last post by:
Hello, I am trying to print something to a print server using the following function but I get errors, does anyone have any pointers? Rgds, Josh Traceback (most recent call last): File...
2
by: siggy2 | last post by:
Hi, I'm using Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 I've noticed a strange (= not deterministic) behaviour of ftplib.py: sometimes (not always) it fails (after a variable number of...
1
by: Manu | last post by:
Hi, ftplib fails to cwd into a directory which contains spaces in it's name.How do i correct this? Regards Manu
4
by: wASP | last post by:
Hi, I'm a newbie starting up with ASP.NET, and I'm getting off to a wonderful start - and when I tell you "wonderful" I'm being sarcastic. My OS is Win 2000 SP4. I've gotten IIS installed,...
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket)....
0
by: Tarun Kapoor | last post by:
------- Code ------ remotepath = "/incoming" f = FTP(host) f.login(username,password) f.cwd(remotepath) localfile ="C:\\test.txt"
1
by: loial | last post by:
Trying to use ftplib.FTP.nlst() method to list the files in a directory on a FTP server. It works fine except when there are no files in the directory. Then it gives the error ...
1
by: Jon Bowlas | last post by:
Hi All, I've written a little method to connect to an ftpserver which works well, however when I send a file using this ftp connection oddly I _sometimes_ get returned an EOFError from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.