473,385 Members | 1,925 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,385 software developers and data experts.

Python FTP - NameError: name 'mydpa' is not defined

Hi there. I am trying to download a file(sn.last) from a public FTP
server with the following code:

from ftplib import FTP
ftp=FTP('tgftp.nws.noaa.gov')
ftp.login()
ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf')
ftp.retrbinar('RETR sn.last', open(mydpa,'wb').write)
ftp.quit()

but got an error message, which I think is normal:

Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
ftp.retrbinary('RETR sn.last', open(mydpa,'wb').write)
NameError: name 'mydpa' is not defined

I don't know much about python, but just try to use the code to
download data. I don't know where the file will be saved to. Is the
mydata a file name or a folder name? where will it be saved to even
if it's working? Please help be fixed the problem step by step? I am
using 2.5.2 by the way.

I really appreciate your help. Thanks.
Jul 28 '08 #1
4 3743
On Jul 28, 2:27*pm, "Harry" <laiyi...@yahoo.cawrote:
Hi there. I am trying to download a file(sn.last) from a public FTP
server with the following code:

from ftplib import FTP
ftp=FTP('tgftp.nws.noaa.gov')
ftp.login()
ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf')
ftp.retrbinar('RETR sn.last', open(mydpa,'wb').write)
open(mydpa,'wb') would open the file to which you're saving the data,
but you haven't defined to mydpa, so Python will complain.
ftp.quit()

but got an error message, which I think is normal:

Traceback (most recent call last):
* File "<pyshell#13>", line 1, in <module>
* * ftp.retrbinary('RETR sn.last', open(mydpa,'wb').write)
NameError: name 'mydpa' is not defined
Yep!
>
I don't know much about python, but just try to use the code to
download data. I don't know where the file will be saved to. Is the
mydata a file name or a folder name? where will it be saved to even
if it's working? Please help be fixed the problem step by step? I am
using 2.5.2 by the way.
You need to tell it where to save the data by defining mydpa.
I really appreciate your help. Thanks.
Jul 28 '08 #2
Ej

I have a similar problem. I need to download the same file every hour
so it will be nice to be able to rename the downloads with a variable
name.

For example in this case:

from ftplib import FTP
ftp=FTP('tgftp.nws.noaa.gov')
ftp.login()
ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf')
ftp.retrbinar('RETR sn.last', open('sn','wb').write)
ftp.quit()

Question: How to achive rename the downloaded files as sn1, sn2,
sn3.... or with a timestamp?
The ftp.rename() is used to rename files on the server, isn't it?I'm
Python shy. Please help.

Any suggestion will be appreciated.

On Jul 28, 11:41*am, MRAB <goo...@mrabarnett.plus.comwrote:
On Jul 28, 2:27*pm, "Harry" <laiyi...@yahoo.cawrote:
Hi there. I am trying to download a file(sn.last) from a public FTP
server with the following code:
from ftplib import FTP
ftp=FTP('tgftp.nws.noaa.gov')
ftp.login()
ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf')
ftp.retrbinar('RETR sn.last', open(mydpa,'wb').write)

open(mydpa,'wb') would open the file to which you're saving the data,
but you haven't defined to mydpa, so Python will complain.
ftp.quit()
but got an error message, which I think is normal:
Traceback (most recent call last):
* File "<pyshell#13>", line 1, in <module>
* * ftp.retrbinary('RETR sn.last', open(mydpa,'wb').write)
NameError: name 'mydpa' is not defined

Yep!
I don't know much about python, but just try to use the code to
download data. I don't know where the file will be saved to. Is the
mydata a file name or a folder name? where will it be saved to even
if it's working? Please help be fixed the problem step by step? I am
using 2.5.2 by the way.

You need to tell it where to save the data by defining mydpa.
I really appreciate your help. Thanks.- Hide quoted text -

- Show quoted text -
Aug 5 '08 #3
Ej wrote:
I have a similar problem. I need to download the same file every hour
so it will be nice to be able to rename the downloads with a variable
name.

For example in this case:

from ftplib import FTP
ftp=FTP('tgftp.nws.noaa.gov')
ftp.login()
ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf')
ftp.retrbinar('RETR sn.last', open('sn','wb').write)
ftp.quit()

Question: How to achive rename the downloaded files as sn1, sn2,
sn3.... or with a timestamp?
you're downloading to the file name you pass to open ("sn" in your
case), so to download to a different file, just pass in another name.

to rename an existing file on the local file system, use os.rename.

</F>

Aug 5 '08 #4
Ej
Hi Fredrik,

Thanks so much for you quick help!!! I googled the os.rename you gave
me and I found solution to solve my problem.

You made my day!


On Aug 5, 10:37*am, Fredrik Lundh <fred...@pythonware.comwrote:
Ej wrote:
I have a similar problem. I need to download the same file every hour
so it will be nice to be able to rename the downloads with a variable
name.
For example in this case:
from ftplib import FTP
ftp=FTP('tgftp.nws.noaa.gov')
ftp.login()
ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf')
ftp.retrbinar('RETR sn.last', open('sn','wb').write)
ftp.quit()
Question: How to achive rename the downloaded files as sn1, sn2,
sn3.... or with a timestamp?

you're downloading to the file name you pass to open ("sn" in your
case), so to download to a different file, just pass in another name.

to rename an existing file on the local file system, use os.rename.

</F>- Hide quoted text -

- Show quoted text -
Aug 5 '08 #5

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

Similar topics

0
by: Dave | last post by:
I have been trying an example from the Python Programming on Win32 book on the lastest versions of python (2.3.3) and win32all (build 163). I create the COM object and try to call it from VB but i...
1
by: Kenneth McDonald | last post by:
I'm setting myself up to use Python with jEdit (after trying jed, VIM, others...urggh.) One small problem I'm having is that while jEdit has a nice plugin called Console which can be set up to run...
17
by: les_ander | last post by:
Hi, i am so use to perl's regular expression that i find it hard to memorize the functions in python; so i would appreciate if people can tell me some equivalents. 1) In perl: $line = "The...
6
by: Patrick Fitzsimmons | last post by:
Hi, I'm sure I should know this, but I can't find it in the manual. Is there a function in Python like the function in PHP isset()? It should take a variable name and return True or False...
134
by: Joseph Garvin | last post by:
As someone who learned C first, when I came to Python everytime I read about a new feature it was like, "Whoa! I can do that?!" Slicing, dir(), getattr/setattr, the % operator, all of this was very...
4
by: rh0dium | last post by:
Hi all, So I have this simple little routine.. say like this.. def foo() return {"a":"b", "b":"c"} if foo(): print "Have foo"
0
by: ycollet | last post by:
Hello, I'm trying to write a program to send python statements to a python server via tcp and then get back results via a tcp connection. It nearly works ... but I'm totally lost with the...
11
by: MonkeeSage | last post by:
A quick question about how python parses a file into compiled bytecode. Does it parse the whole file into AST first and then compile the AST, or does it build and compile the AST on the fly as it...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...

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.