Questions tagged [ftplib]

ftplib — FTP protocol client under Python programming language

ftplib is a python module which defines the class FTP and a few related items.

The FTP class implements the client side of the FTP protocol. You can use this to write Python programs that perform a variety of automated FTP jobs, such as mirroring other ftp servers. It is also used by the module urllib.request to handle URLs that use FTP. For more information on FTP (File Transfer Protocol), see Internet RFC 959.

Read more about ftplib at python docs..

681 questions
80
votes
7 answers

How to download a file via FTP with Python ftplib

I have the following code which easily connects to the FTP server and opens a zip file. I want to download that file into the local system. How to do that? # Open the file for writing in binary mode print 'Opening local file ' + filename file =…
Intekhab Khan
  • 1,775
  • 4
  • 18
  • 28
46
votes
3 answers

File size differences after copying a file to a server vía FTP

I have created a PHP-script to update a web server that is live inside a local directory. I'm migrating the script into Python. It works fine for the most part, but after a PUT command, the size of the file appears to change. Thus, the size of the…
PabloG
  • 25,761
  • 10
  • 46
  • 59
40
votes
1 answer

TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader

I'm trying to iterate through a group of files in a folder on my local machine and upload only ones where the file names contain "Service_Areas" to my FTP site using using this code (Python 3.6.1 32 bit, Windows 10 64 bit): ftp =…
Matt
  • 967
  • 2
  • 9
  • 23
39
votes
2 answers

Is it possible to read FTP files without writing them using Python?

I am trying to read files using Python's ftplib without writing them. Something roughly equivalent to: def get_page(url): try: return urllib.urlopen(url).read() except: return "" but using FTP. I tried: def get_page(path): …
aensm
  • 3,325
  • 9
  • 34
  • 44
36
votes
7 answers

Python FTP implicit TLS connection issue

I have a need to connect to FTPS server to which I am able to connect successfully using lftp. However, when I try with Python ftplib.FTP_TLS, it times out, the stack trace shows that it is waiting for the server to send welcome message or like.…
Rg Glpj
  • 423
  • 2
  • 5
  • 10
35
votes
6 answers

Python-FTP download all files in directory

I'm putting together a script to download all the files from a directory via FTP. So far I have managed to connect and fetch one file, but I cannot seem to make to work in batch (get all the files from the directory) Here is what I have so far: from…
Sosti
  • 351
  • 1
  • 4
  • 4
30
votes
4 answers

Python ftplib - specify port

I would like to specify the port with Python's ftplib client (instead of default port 21). Here is the code: from ftplib import FTP ftp = FTP('localhost') # connect to host, default port Is there an easy way to specify an alternative port?
user284244
27
votes
2 answers

How to get FTP file's modify time using Python ftplib

I'm trying to load a CSV file to Amazon S3 with Python. I need to know CSV file's modification time. I'm using ftplib to connect FTP with Python (2.7).
Uygar
  • 273
  • 1
  • 3
  • 6
23
votes
5 answers

Python: Open a Listening Port Behind a Router (upnp?)

I've developed an application that is essentially just a little ftp server with the ability to specify which directory you wish to share on startup. I'm using ftplib for the server because it's sick easy. The only issue I'm having is that if you are…
Boona
  • 239
  • 1
  • 2
  • 3
20
votes
16 answers

ftplib checking if a file is a folder?

How can i check if a file on a remote ftp is a folder or not using ftplib? Best way i have right now is to do a nlst, and iterate through calling size on each of the files, if the file errors out then it is a folder? Is there a better way? I cannot…
UberJumper
  • 20,245
  • 19
  • 69
  • 87
19
votes
5 answers

Python FTP get the most recent file by date

I am using ftplib to connect to an ftp site. I want to get the most recently uploaded file and download it. I am able to connect to the ftp server and list the files, I also have put them in a list and got the datefield converted. Is there any…
krisdigitx
  • 7,068
  • 20
  • 61
  • 97
18
votes
7 answers

Upload folders from local system to FTP using Python script

I have to automatically upload folders to an FTP using a Python script. I am able to upload a single file, but not folders with subfolders and files in them. I did a lot of search, but failed. Could some one help me out here? Thanks in advance. #!…
Rakesh
  • 81,458
  • 17
  • 76
  • 113
18
votes
6 answers

Downloading a directory tree with ftplib

This will not download the contents of sub-directories; how can I do so? import ftplib import configparser import os directories = [] def add_directory(line): if line.startswith('d'): bits = line.split() dirname = bits[8] …
Anthony Lemmer
  • 181
  • 1
  • 1
  • 4
18
votes
2 answers

FTPS with Python ftplib - Session reuse required

So, I am trying to connect to an FTP server to get directory listings and download files. But the first command after the prot_p() function is raising an exception - Producing these errors from the log: *get* '150 Here comes the directory…
slat
  • 306
  • 1
  • 3
  • 5
17
votes
1 answer

SFTP using ftplib

I need to download a file from a host using SFTP. Do you know if is it possible to do that using Python ftplib? I saw an example here, but when I try to connect I receive EOFError. I tried this code: import ftplib ftp = ftplib.FTP() ftp.connect(…
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
1
2 3
45 46