When I try to run your code:
First: the FTP issue. It won't do anything, so I just wanted to see what happens when I execute this small script:nluug is an anynomous FTP server that is good for testing.Code:
import ftplibfrom ftplib import FTPsession = ftplib.FTP('ftp.nluug.nl')FTP.size('README.nluug')FTP.quit()
So many issues in 5 lines of code...
I don't have time to itemize/explain them all.
Perhaps this worked example will help -from ftplib import FTPCode:
david@rp54bw64full0512:~/Support/niels $ pythonPython 3.11.2 (main, May 2 2024, 11:59:08) [GCC 12.2.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> from ftplib import FTP>>> remote = FTP('ftp.nluug.nl')>>> remote.login()'230 Login successful.'>>> remote.dir()lrwxrwxrwx 1 0 0 1 Nov 13 2012 ftp -> .lrwxrwxrwx 1 0 0 3 Nov 13 2012 mirror -> pubdrwxr-xr-x 23 0 0 4096 Apr 22 17:34 pubdrwxr-sr-x 85 0 450 4096 Jun 24 17:09 sitedrwxr-xr-x 9 0 0 4096 Jan 23 2014 vol>>> remote.cwd('pub')'250 Directory successfully changed.'>>> remote.dir()lrwxrwxrwx 1 504 450 14 Nov 02 2007 FreeBSD -> os/BSD/FreeBSDlrwxrwxrwx 1 504 450 20 Nov 02 2007 ImageMagick -> graphics/ImageMagicklrwxrwxrwx 1 504 450 13 Nov 02 2007 NetBSD -> os/BSD/NetBSDlrwxrwxrwx 1 504 450 14 Nov 02 2007 OpenBSD -> os/BSD/OpenBSD-rw-rw-r-- 1 504 450 926 Apr 22 17:28 README.nluug-rw-r--r-- 1 504 450 2023 May 03 2005 WhereToFindWhat.txtdrwxr-sr-x 2 0 450 4096 Jan 26 2008 avdrwxrwsr-x 2 0 450 4096 Aug 12 2004 compdrwxrwsr-x 2 0 450 4096 Mar 24 2000 cryptodrwxr-xr-x 2 500 450 4096 Apr 10 2014 dblrwxrwxrwx 1 0 0 21 Feb 22 2017 debian -> os/Linux/distr/debiandrwxrwsr-x 2 0 450 4096 Mar 29 2009 documentsdrwxrwsr-x 2 0 450 4096 Dec 01 2008 editors-rw-r--r-- 1 0 0 43 Jun 15 2013 favicon.icolrwxrwxrwx 1 0 450 1 Nov 02 2007 ftp -> .drwxrwsr-x 3 0 450 4096 Dec 23 2015 gameslrwxrwxrwx 1 504 450 27 Nov 02 2007 gnu -> ../site/ftp.gnu.org/pub/gnu-rw-r--r-- 1 0 450 54 Jan 04 2013 google6e904a3e38fc0293.htmldrwxrwsr-x 2 0 450 4096 Jan 03 2013 graphicslrwxrwxrwx 1 504 450 29 Nov 02 2007 ibiblio -> ../site/ibiblio.org/pub/Linuxlrwxrwxrwx 1 500 450 29 Nov 02 2007 infomac -> ../site/info-mac.org/info-macdrwxrwsr-x 3 500 450 4096 Oct 22 2021 internetlrwxrwxrwx 1 0 0 13 Feb 24 2017 kiwix -> ../site/kiwixlrwxrwxrwx 1 504 450 22 Nov 02 2007 knoppix -> os/Linux/distr/knoppixdrwxrwsr-x 5 0 450 4096 Mar 23 2014 languagesdrwxrwsr-x 3 0 450 4096 Jun 21 2000 maildrwxr-xr-x 2 0 0 4096 Oct 20 2015 mapsdrwxr-xr-x 2 500 450 4096 Feb 21 2023 mediaplayerlrwxrwxrwx 1 500 450 35 Nov 02 2007 netscape -> ../site/mirrorsite.netscape.com/pubdrwxrwsr-x 2 500 450 4096 Mar 09 2010 networkingdrwxrwsr-x 2 0 450 4096 Feb 21 2000 newslrwxrwxrwx 1 0 450 41 Nov 02 2007 nilo -> ../site/darkstar.welcomehome.org/pub/nilodrwxrwsr-x 2 504 450 4096 Mar 03 2011 officedrwxrwsr-x 7 0 450 4096 Feb 21 2023 osdrwxrwsr-x 2 504 450 4096 Jan 30 2013 programminglrwxrwxrwx 1 504 450 1 Nov 02 2007 pub -> .-rw-r--r-- 1 0 450 189 Apr 22 17:34 robots.txtdrwxrwsr-x 2 0 450 4096 Jun 18 2002 securitylrwxrwxrwx 1 0 0 12 May 26 2014 test -> ../site/testdrwxrwsr-x 2 0 450 4096 Mar 09 2010 textproclrwxrwxrwx 1 0 450 30 Mar 29 2009 video -> ../site/ftp.nluug.nl/pub/videolrwxrwxrwx 1 504 450 11 Nov 02 2007 vim -> editors/vimdrwxrwsr-x 3 0 450 4096 Jan 23 2014 windowing>>> remote.size('README.nluug')926>>>
remote = FTP('ftp.nluug.nl')
remote.login()
On windows I get no return and on my pi I get this:
Can somebody please explain how to start? I have no idea what I am doing wrong and how to learn this stuff. I have googled for hours, but can't find good, explainable resources. What I need is the level of "how to boil an egg?" that explains what an egg is, what a pan is, what water is, how to get the egg in the pan, how to get water in the pan etc.^CTraceback (most recent call last):
File "/home/pi/ftp3.py", line 2, in <module>
remote = FTP('ftp.nluug.nl')
File "/usr/lib/python3.9/ftplib.py", line 119, in __init__
self.connect(host)
File "/usr/lib/python3.9/ftplib.py", line 156, in connect
self.sock = socket.create_connection((self.host, self.port), self.timeout,
File "/usr/lib/python3.9/socket.py", line 831, in create_connection
sock.connect(sa)
KeyboardInterrupt
Most resources just write: put egg in boiling water for 5 minutes.
Why did you change "session =" for "remote =" for example? What do both do, when do I use one, when the other? Why is mine wrong?
Statistics: Posted by nielsgeode — Mon Jul 01, 2024 11:18 am