473,670 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem when getting ftp file

I'm new to python and I'm not sure if I use the ftplib
class correctly.

I made a programm to update a pseudo-dynamic site via
ftp. The site is a static html that include files
update by ftp. It create 2 files, and html and a .dat
file, which hold a easier to manipulate data.

first of all, when I start the application, it connect
to ftp, and get the .dat files on the ftp server to
stay up to date. Then modification are done to the
local file, when the application receive a update
request, it take the local file and update it to the
server.

The update work perfectly, but the part I get the file
from ftp cause me some trouble. The client app is run
on windows. To create the file and to read it, I use
open("myfile.da t").write and readlines, there's no
problem, but when I get a new file from ftp, the
return line disapear and readlines take the all the
file as one line.

To write the new file in ftp I use :
storlines("STOR ", open("myfile.da t").read)
And to get it I use :
retrlines("RETR ", open("myfile.da t").write)
If someone can guide me where to look to find a
solution, it will be appreciated.

Thank you
_______________ _______________ _______________ _____________
Lèche-vitrine ou lèche-écran ?
magasinage.yaho o.ca
Jul 18 '05 #1
2 1835
> The update work perfectly, but the part I get the file
from ftp cause me some trouble. The client app is run
on windows. To create the file and to read it, I use
open("myfile.da t").write and readlines, there's no
problem, but when I get a new file from ftp, the
return line disapear and readlines take the all the
file as one line.
It sounds like your loosing new lines because of the way your using text
and binary file options. When you open a file with python you can open
it as "r" or "rb" mode in the open statement. For writing it's "w" or
"wb". With the "b" (binary) data is transfered unchanged. Without it,
python will translate newlines \n to \r\n on output and then translate
\r\n to \n on input. This is because different systems use different
textual line terminators -- linux=\n, windows=\r\n, and mac=\r.

I think FTP also has text and binary transfer modes -- too. As a
result, you need to choose all of these combinations carefully.
To write the new file in ftp I use :
storlines("STOR ", open("myfile.da t").read)
And to get it I use :
retrlines("RETR ", open("myfile.da t").write)


By the way, the write above looks wrong to me. Don't you need to use
open("myfile.da t","w")?

Rob

Jul 18 '05 #2
> The update work perfectly, but the part I get the file
from ftp cause me some trouble. The client app is run
on windows. To create the file and to read it, I use
open("myfile.da t").write and readlines, there's no
problem, but when I get a new file from ftp, the
return line disapear and readlines take the all the
file as one line.
It sounds like your loosing new lines because of the way your using text
and binary file options. When you open a file with python you can open
it as "r" or "rb" mode in the open statement. For writing it's "w" or
"wb". With the "b" (binary) data is transfered unchanged. Without it,
python will translate newlines \n to \r\n on output and then translate
\r\n to \n on input. This is because different systems use different
textual line terminators -- linux=\n, windows=\r\n, and mac=\r.

I think FTP also has text and binary transfer modes -- too. As a
result, you need to choose all of these combinations carefully.
To write the new file in ftp I use :
storlines("STOR ", open("myfile.da t").read)
And to get it I use :
retrlines("RETR ", open("myfile.da t").write)


By the way, the write above looks wrong to me. Don't you need to use
open("myfile.da t","w")?

Rob
Jul 18 '05 #3

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

Similar topics

4
1777
by: Vannela | last post by:
I want to open a new file and keep on appending the text depending on some condition. I have used this code but it is not appeneding properly It is giving some numbers in the output file if(index=="3") { files=new FileStream (filetext1.Text+"\\"+tgname+"\\"+"GlobalDeclarations"+".cs"
1
2317
by: a_rybicki | last post by:
"Hi - I'm experiencing something strange when I call a FileOpenDialog from a dialog box in my application (Borland C++ 6). Basically, here's the scenario: - Open my own child dialog from the main window. - Click on a "browse" button to open the FileOpen dialog. My dialog allocates the TData and TFileOpenDialog and then Execute()'s it.
11
6412
by: Marcus Jacobs | last post by:
Dear Group I have encountered a problem with fclose and I am wondering if anyone could provide some insight about this problem to me. Currently, I am working on a small personal project that is requiring for me to alter some existing code to a program. While running the unaltered code, I kept encountering an application (The exception unknown software exception(0xc00000fd) etc. .. etc... etc... I am running W2K Pro). Through a bit of...
11
6621
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to transfer data across.On the serve I am using Socket 2 API (recv function to read bytes)and not using ..NET. I use FileStream to open the file on the pocket pc, then associate a BinaryReader object with the stream and call ReadBytes to read all the...
3
3053
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about the event in a typical form with textboxes, drop down lists, etc. On this page there are also 4 file upload controls where the user can select 0 to 4 images on their file system for inclusion in the event listing. On submit, the images (if any)...
6
1389
by: Dave | last post by:
This is such a "dead in the water" problem I don't even know if this is the right forum for it. I have developed an ASP.NET/C# project on my own PC and it's working. I then transferred it to the remote serverwhere it will finally reside. I'm not a server expert, but the administrator says that ASP.NET is enabled. However, when I access any of the pages I just get a generic "Server Error in '/' Application. Runtime Error" page that tells me...
4
7562
by: kthiagar | last post by:
Hi I am trying to connect to a password protected access file from VB.NET. I have no problem in connecting to Access, if I remove the password. This is what I am doing: In the server explorer, I choose "Add a connection" Choose "Microsoft Jet 4.0 OLEDB Provider" in the provider tab Selected the access file in the next tab Left Username as Admin and typed the password. Now when I try to test connection, I am getting this error message:
6
2340
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system (bash to be precise). All you need to know is that there are four classes. (Of course, you may...
6
2269
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome – he was feeling uncomfortable taking Bunty to public places along with him. People would stare at them all the while. At one point, Luycha could not stand it anymore and he decided to do some justice to his name. He started looking for a new hope in...
11
7108
by: mjahabarsadiq | last post by:
Hi I have created a web application. I am using ant to build the war and deploy in tomcat. The war file is deployed under "TOMCATE_HOME/work/standalone/localhost/onlineres.war". I have my source files in "D:\Sadiq\Projects\Onlineres". The folder structure is as follows. 1) D:\Sadiq\Projects\Onlineres: This folder is having the context.xml, web.xml, build.xml and build.properties files.
0
8466
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7412
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6212
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1791
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.