Python Forum
FTP not downloading files but showing success
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FTP not downloading files but showing success
#1
Hi,

I am new to python.....but have good Unix background.

I was trying to have ftp download a file from remote server to my local unix server.....

import ftplib
ftp = ftplib.FTP(some remote server)
ftp.login(uid,pass)
ftp.pwd()
ftp.cwd('/var/tmp')
ftp.dir()

ftp.retrlines('RETR somefile')

Now what is happening is, I am getting all the messages for dir listing, path etc... and finally am getting "226 file transfer successful".

But the directory where I ran the above code when checked, I didnt find the file downloaded there. Not sure what I have missed.

When I tried to check similar code on the net, found that some guys are opening a local file in write mode and downloading the contents of remote file in it. I find this unnecessary as why cant we just get the file in its entirety as we do in unix ftp session. Why should I be required to create a file at local server in write mode and then dump contents from remote file in it?

Please let me know if I have understood this correctly and please help.

Thanks,
PL
Reply
#2
looking at docs, I think you do need to open a local file to write (i.e. the callback).

There is example with ftp.retrbinary
and for retrline the default callback is stdout

Quote:FTP.retrbinary(command, callback[, maxblocksize[, rest]])

   Retrieve a file in binary transfer mode. command should be an appropriate RETR command: 'RETR filename'. The callback function is called for each block of data received, with a single string argument giving the data block. The optional maxblocksize argument specifies the maximum chunk size to read on the low-level socket object created to do the actual transfer (which will also be the largest size of the data blocks passed to callback). A reasonable default is chosen. rest means the same thing as in the transfercmd() method.

FTP.retrlines(command[, callback])

   Retrieve a file or directory listing in ASCII transfer mode. command should be an appropriate RETR command (see retrbinary()) or a command such as LIST, NLST or MLSD (usually just the string 'LIST'). LIST retrieves a list of files and information about those files. NLST retrieves a list of file names. On some servers, MLSD retrieves a machine readable list of files and information about those files. The callback function is called for each line with a string argument containing the line with the trailing CRLF stripped. The default callback prints the line to sys.stdout.
Reply
#3
Hmm thought so, Thanks dude!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Downloading time zone aware files, getting wrong files(by date))s tester_V 9 1,032 Jul-23-2023, 08:32 AM
Last Post: deanhystad
  Downloading images from webpages H84Gabor 2 1,887 Sep-29-2021, 05:39 PM
Last Post: snippsat
  how to import files in Google Collab wihout downloading them to PC and to Google Disk sveto4ka 9 3,889 Jun-03-2020, 12:40 PM
Last Post: sveto4ka
  Downloading And Saving Zip Files To A Particular Path Folder eddywinch82 2 2,561 Jan-06-2020, 07:56 PM
Last Post: eddywinch82
  Identifying string success flag graham23s 4 3,108 Aug-14-2019, 09:27 PM
Last Post: graham23s
  Downloading a module Xlsxwriter dan789 6 11,251 Jan-26-2019, 02:13 PM
Last Post: dan789
  Why does pyinstaller register success with py to exe, but? Pleiades 1 4,285 May-09-2018, 11:02 AM
Last Post: Pleiades
  No success with PyInstaller j.crater 2 7,062 Mar-10-2018, 10:29 PM
Last Post: j.crater
  "if statement" and downloading a dataset Alberto 1 2,486 Jan-25-2018, 01:44 PM
Last Post: ka06059
  Downloading and using pyperclip PMPythonlearner 2 5,045 Dec-31-2017, 04:37 PM
Last Post: PMPythonlearner

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020