FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old October 1st, 2003, 09:23 AM
goudaman goudaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 26 goudaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 34 sec
Reputation Power: 0
searching FTP directory (getting foldernames as variable)

hi!

I'm trying to get a folder name in a ftp path into a variable.

As I'm trying to get the newest folder, and I cant know what its called, I'm trying to access the info a:
f.retrlines("LIST")
returns...
unfortunately only the server response gets stored...

anybody know how to get the whole list into a string? or a tuple? or whatever?

heres my test script:

Code:
def latestFTP(country,city):
     ftpHost="localhost"
     ftpUser="chris"
     ftpPasswd="chris"
     mainPath = "etv/"
     curDir = mainPath + country + "/" + city + "/" 
     f = ftplib.FTP(host=ftpHost,user=ftpUser,passwd=ftpPasswd)
     f.cwd(curDir)
     directorylist = f.retrlines("LIST")
     print directorylist
     f.quit()

even though the print returns the whole directory, only the server response is in the string.

any suggestions gladly appreciated!

Cheers

Chris

Last edited by goudaman : October 1st, 2003 at 09:27 AM.

Reply With Quote
  #2  
Old October 1st, 2003, 11:03 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I've looked at the docs on the ftplib module (http://www.python.org/doc/current/lib/ftp-objects.html). The problem is that retrlines() doesn't actually return it's results, instead it outputs them to sys.stdout.. when using the default callback function anyway.

On the other hand nthe lst() function seems to do what you want

Quote:
nlst( argument[, ...])

Return a list of files as returned by the "NLST" command. The optional argument is a directory to list (default is the current server directory). Multiple arguments can be used to pass non-standard options to the "NLST" command.


Now i have NO idea what the NLST command is so i could be mistaken here , another aproch might be to use sendcmd()..

Quote:
sendcmd( command)

Send a simple command string to the server and return the response string.


Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old October 1st, 2003, 11:33 AM
goudaman goudaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 26 goudaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 34 sec
Reputation Power: 0
thanks! I seem to have overread that!

now what do i do with the
<PyShell.PseudoFile instance at 0x00A39C60>
?


how can i access the "contents"?

cheers a bunch!

chris

Reply With Quote
  #4  
Old October 1st, 2003, 11:43 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Ah ok , what returned that? What function did you go for.. post some more code dude

Mark.

Reply With Quote
  #5  
Old October 2nd, 2003, 04:07 AM
goudaman goudaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 26 goudaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 34 sec
Reputation Power: 0
ok that one whas crap....

i put a
Code:
print sys.stdout
in and forgot about it...
stupid enough...

ok
when i put:
Code:
 

def latestFTP(country,city):
    import sys
    lastEntryTime = "031001"
    ftpHost="localhost"
    ftpUser="chris"
    ftpPasswd="chris"
    mainPath = "etv/"
    curDir = mainPath + country + "/" + city + "/" 
    f = ftplib.FTP(host=ftpHost,user=ftpUser,passwd=ftpPasswd)
    f.cwd(curDir)
    directoryList = f.nlst(curDir)
    print directoryList
    f.quit()
    lastEntryTime = "032023"
    return lastEntryTime


returns:

Code:
[]
'032023'


so wheres the contents for [] ... argh.
i guess nlst lists files only and not the folders

Reply With Quote
  #6  
Old October 2nd, 2003, 04:34 AM
goudaman goudaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 26 goudaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 34 sec
Reputation Power: 0
got it... d'oh!

the
f.cwd(curDir)

and the
f.nlst(curDir)

didnt fit together...

f.nlst()

gives:

['031001', '031002', '031003']

(all the folder names)

but cheers to you for the right anwser!

chris

Reply With Quote
  #7  
Old October 2nd, 2003, 07:47 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
knew ya would, i was a lil shocked myself when you gave me a memory location i.e. <Py...>

Python's great! but it does take a while to get to know it's stardard library, it's just so full.. and thats without adding some of the other nice modules, numarry, psyco, PIL, mysqldb, sqlite etc.

Mark.

Reply With Quote
  #8  
Old October 6th, 2003, 03:24 AM
goudaman goudaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 26 goudaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 34 sec
Reputation Power: 0
true true.... and I havent even scratched on those


but one more thing:

how about getting the "newest" file/folder ?

even though the retrlines giver the date, i cant find a way to acces the date info...

i guess i'm not looking properly.... any hints?


cheers

Chris

Reply With Quote
  #9  
Old October 6th, 2003, 05:48 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I can't see a function which will let you do this in ftplib, i think your best bet would be to use cwd() to set the current working directory and then use sendcmd() with 'LIST' or a similar ftp command to retrieve your data , depending on how his data is returned it may need to be split apart etc.

Have fun,
Mark

Reply With Quote
  #10  
Old October 8th, 2003, 09:57 AM
goudaman goudaman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 26 goudaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 33 m 34 sec
Reputation Power: 0
hmm
the f.sendcmd("list") doesnt work
gives me a

550 List failed. No port specified.

From what i could find out, this is because of the passive mode. but even when i change that on the ftp server, its the same.

dont i love it?

i guess not

Reply With Quote
  #11  
Old October 8th, 2003, 05:12 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Ah ok, this makes total sence , you could try passing port as an argument somewhere.. There's an optional acct argument with FTP but i dont know what thats for?

I really have no idea is this a thing with your servers setup? Also you might look into an FTP command which returns the last modified if such a command exists.. in any case i think the answer lies in FTP commands, why retrlines() can't just return a value is beond me!

If your feeling confident you could always crack open the ftplib module and make a few changes, i'm not exactly sure how it works since i havn't looked inside..

Anyway have fun Chris,

Marky.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > searching FTP directory (getting foldernames as variable)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |