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 April 20th, 2004, 11:47 AM
flixxer flixxer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 44 flixxer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Another FTP question

I have a problem when retrieving text file from FTP server, the formatting will lost(the line part) eg:
Code:
--- The original file --
1st line
2nd Line

-------- the retrived file -----
1st line2nd Line


but transfering file to the server is fine.

Reply With Quote
  #2  
Old April 20th, 2004, 12:16 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,187 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 10 h 59 m 3 sec
Reputation Power: 251
Try retrieving in binary mode. The only difference between text mode and binary is that in text mode it will try to change the line endings to match the convention of your system. In your case it looks like it is getting it wrong. If you use binary mode then it will do no translation and you should get the file back exactly as it is on the server.

You need to make sure that the file object that you create to save the file is opened in the same mode, or that may change the line endings as well.

Dave - The Developers' Coach

Reply With Quote
  #3  
Old April 20th, 2004, 03:09 PM
flixxer flixxer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 44 flixxer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Quote:
Originally Posted by DevCoach
You need to make sure that the file object that you create to save the file is opened in the same mode, or that may change the line endings as well.

Dave - The Developers' Coach


I didn't really get that part.Can you explain it further??

Reply With Quote
  #4  
Old April 21st, 2004, 08:31 AM
flixxer flixxer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 44 flixxer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Ok.. I've tried using binary mode anbd it works thanks.Another question, how can I divide a path to a file so each patn/or directory is saved as a variable, for example:
Code:
path = tem/dir1/xml.txt

so I can get it this way

 level1 = temp
 level 2 = dir1
 file = xml.txt


Thnak you.

Reply With Quote
  #5  
Old April 21st, 2004, 01:00 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,187 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 10 h 59 m 3 sec
Reputation Power: 251
Quote:
Originally Posted by flixxer
Ok.. I've tried using binary mode anbd it works thanks.Another question, how can I divide a path to a file so each patn/or directory is saved as a variable, for example:
Code:
path = tem/dir1/xml.txt

so I can get it this way

 level1 = temp
 level 2 = dir1
 file = xml.txt


Thnak you.


If you know how many levels there are then you can do it like this:
Code:
>>> import os
>>> myPath = 'temp/dir1/xml.txt'
>>> myPath, file = os.path.split(myPath)
>>> myPath, level2 = os.path.split(myPath)
>>> myPath, level1 = os.path.split(myPath)
>>> myPath, level1, level2, file
('', 'temp', 'dir1', 'xml.txt')


If you don't know how many levels then you will need to loop round and append the result to a list.

Alternatively if you know what the separator is, you can use string.split:

Code:
>>> myPath = 'temp/dir1/xml.txt'
>>> level1, level2, file = myPath.split('/')


However this is platform dependant, since the separator is different on different OSs. You can use os.sep to get the separator character being used, but Windows allows both '/' and '\' as separators, so you can end up with a mixture. A call to os.path.normpath() will change them to '\'.

Code:
>>> path = r'temp\dir1/xml.txt'
>>> level1, level2, file = os.path.normpath(path).split(os.sep)
>>> level1, level2, file
('temp', 'dir1', 'xml.txt')


Dave - The Developers' Coach

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > Another FTP question


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway