0

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 http://cathalstewart.co.uk/pi/terminal_error.png

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

Raspberry Pi Error http://cathalstewart.co.uk/pi/terminal_working.png

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

1 Answer 1

0

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)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.