list from FTP server to a text file
Ahmed, Shakir
shahmed at sfwmd.gov
Thu Jan 6 11:48:16 EST 2011
-----Original Message-----
From: python-list-bounces+shahmed=sfwmd.gov at python.org
[mailto:python-list-bounces+shahmed=sfwmd.gov at python.org] On Behalf Of
Dan M
Sent: Thursday, January 06, 2011 11:06 AM
To: python-list at python.org
Subject: Re: list from FTP server to a text file
On Thu, 06 Jan 2011 10:51:42 -0500, Ahmed, Shakir wrote:
> Hi,
>
> I am trying to create a list in a txt file from an ftp server. The
> following code is retrieving the list of the files but could not able
to
> write in a text file. Any help is highly appreciated.
>
> Thanks
>
>
>
> ****************************
> import os
> import time
> from ftplib import FTP
> ftp = FTP("*.org","","") # connect to host, default port ftp.login()
> ftp.cwd("/pub/remotefolder/")
> ftp.retrlines('NLST')
> ******************************
WARNING: I am a newbie! Expect more pythonic ways to do this in other
replies
from ftplib import FTP
ftp = FTP("host", "user", "pass")
ftp.cwd("/pub/myfolder")
files = ftp.nlst(".")
f = open('files.txt', 'w')
for file in files:
f.write('%s\n' % (file,))
f.close()
--
It worked
Thanks,
shk
More information about the Python-list
mailing list