Sign up ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I have been trying to read a simple two line text file from a remote server using ftplib. The simple script shown below works fine from my Ubuntu laptop but will not work from my Raspberry Pi's.

#! /usr/bin/env python

import ftplib

ftp = ftplib.FTP('my_ftp_host','my_ftp_username','my_ftp_password')

myfiles = ftp.dir()

print myfiles

read_file = open("songs.txt", "r")

my_file_data = read_file.readlines()

print my_file_data[0]
print my_file_data[1]

read_file.close()
ftp.quit()

Below is a screenshot of my terminal window on my Raspberry Pi where I get this error even though the file (songs.txt) is there?

Traceback (most recent call last):
File "read_test.py", line 11, in <module>
read_file = open("songs.txt", "r")
IOError: [Errno 2] No such file or directory: 'songs.txt'

Raspberry Pi Error

And the picture below is from the terminal screen on my laptop which works fine.

Raspberry Pi Error

I have tested on both model A (wifi) and model B (wired) running the latest version of Raspbian.

Both the Pi's and my laptop are using Python 2.7.3

I can not understand why this will work on my laptop and not from the Pi? Any help is very much appreciated, Kyle

share|improve this question

closed as off-topic by lenik, RPi Awesomeness, syb0rg, Impulss, Butters Feb 27 '14 at 16:22

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – lenik, RPi Awesomeness, syb0rg, Impulss, Butters
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 0 down vote accepted

this is trying to open a file on your local disk, not on the ftp server:

read_file = open("songs.txt", "r")

you definitely need to download the file from server first with:

with open( filename, 'wb' ) as file :
    ftp.retrbinary('RETR %s' % filename, file.write)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.