Python 3 Programming Tutorial - ftplib FTP transfers Python
Skills:
Python for Data70%
Key Takeaways
This video tutorial covers the use of ftplib, a Python module for FTP file transfers, including uploading and downloading files to and from a remote server. The tutorial provides a working example of how to use ftplib to transfer files, including how to login, navigate directories, and upload and download files.
Full Transcript
hello everybody what is going on welcome to another Python 3 tutorial video in this video we're going to be talking about FTP lib so if you're coming from mot lib I misspoke it's not subprocess we've already covered that uh it's FTP lib so what are we going to do with FTP lib well we're going to use FTP which is file transfer protocol um so the idea of FTP is so you can transfer files to and from uh a remote server now today um I wouldn't necessarily suggest that you use FTP a lot of shared hosting uses FTP and you can't even disable it um but FTP is not really the most secure way or the safest way to transfer files so if you have like highly sensitive information should should probably be using SSH um and encrypting everything um but FTP is still definitely used today it's pretty popular um you can even use SFTP which is like secure fftp um but anyway a lot of people still are using FTP and if it's just something like like a basic transfer that you're just trying to initiate uh FTP lib is actually a really great uh thing to use with python so with that let's go ahead and get started with FTP lib so it's be kind of hard for me to show you guys FTP lib just simply because you have to fill in like a lot of credentials to FTP lib but I'm just going to show you an example that is a working example and feel free to fill in your own credentials but I'm not going to show any credentials in this video so anyway uh what first what we want to do is from FTP lib import Capital FTP and what this is doing is FTP lib is part of your standard Library you don't have to download anything and then we're importing just a part of FTP lip then what we're going to do is we're going to just undercase FTP equals FTP and then in here you're going to put uh domain domain name.com so whatever your domain name is that's what you put in there then you want to Institute a login so we're going to say FTP uh. login oops ftp.com name it's going to uh bring you into exactly that domain name so the home directory of that or the root directory um if you have sh hosting say you have like 15 domain names when you first connect even if you choose this domain name here if that's your main uh domain name or actually not even if that's your main domain name really a domain name just translates to an IP address so when you connect to that IP address you're going to connect to the root directory unless this FTP user does not have access and then they might they might connect to their specific directory um but if this is a user that has access to everything you're going to connect actually to the root directory despite what domain name you type in there so generally the next thing you might need to do is ftp.com [Music] um or location so you might also want to specify uh SLB bar/ www SL um you know whatever in there so if you're let's say you're uploading web files so uh that's what you might need to do you might not need to do that so just obviously everyone's U specific scenario might be a little bit different there but that's how you can change it if you need to now I want to specify we're going to create a couple of functions here the first function generally you're going to do one of two things you're going to send a file or you're going to receive a file okay so first let's talk about taking a file so we're going to say Define grab file and grab file is going to say uh first we need to know what F what's the name of the file that we want to grab so we're going to say file name equals um file name. file in fact let's say f. text just so people don't think you have to add do file there um and then you want to specify where um where do we want this file to go so the way that we can do this is we can say local file equals open uh file name and then open with the intention to WB so now uh what we're going to say is FTP do retar binary and then we're going to make a little bit of a command here and it's going to be RAR so retrieve and then plus the file name okay and then you want to spe specify the uh where it's going and it's local file. right and then finally we're going to specify the buffer um 1024 is fine you really can use probably even up to like 40 60 whatever but we'll use 1024 for now um so 1024 will be good and then whenever you're done you always want to do FTP do quit and then finally we also need to local file. close to close the actual file here okay so uh let's run through this one last time we've made a function it's called grab file this is grabbing the file from the remote server we specify the name of the file we want to grab and we're kind of doing that first just because we we want the name of the file on the server to be the same name that it is when we've grabbed it but you could change these if you wanted so then we're saying the file name is that local file we're specifying we're going to call it that same file name we're opening with uh WB and then we're saying FTP retrieve and then we're we're saying we want to retrieve plus the file name that we want to retrieve so this is remote and then what we would specify next is local thing that we want to do and we're going to do local file. write and then this is just the buffer so how fast we want to or how much data we want to transfer at any given time that's basically what buffer is then when we're all done we want to be able to we want to close that connection we don't want to leave that connection open and then we want to close the file because again it's just like a connection you don't want to leave that file open otherwise you won't be able to modify it again later um so that's grabbing files bya FTP now we can say Define Place file entty parameters and again uh this one's a little easier but we're still going to have file name and the file name will be fil name. text and then also what we're going to do now is we don't actually really need to do local file necessarily but we can do FTP do store binary and what we're going to do here now is store space plus the file name and actually let's see here we've cheated let's change these to undercase for now otherwise the script actually wouldn't have worked lied to you guys store plus file name and then open file name uh and then RB here and then uh we'll do FTP do quit Okay so so what we've done this is our remote file local file how are we doing it we're storing binary what uh what what is it it's going to be store and then the file name that we've specified which is fil name. text and then open a file name we're reading binary here into uh the store binary and then we're storing it basically uh as the file name that we specified okay so uh again we we can grab a file with the following here and we can place a file with the following here and that's really it that's all you have to do and let me just look through here one more time since I didn't I'm not actually running this uh because this is all invalid data here um but this should act this should run finally fin text Tex F yeah and anyway so this is how you can read or grab files and place files from a remote server or even really a computer if you've got FTP on there um so that's that's all there is to it it's actually not not too complex so if you guys have any questions or comments or maybe if I did screw something up here uh let me know [Music] um yeah so anyways uh that's it that's all I really want to show with FTP lib um so as always thanks for watching thanks for all the support and subscriptions and until next time
Original Description
In this Python 3 tutorial video, we cover ftplib. Ftplib is a module that is part of the standard library, so there is no need to install anything. The idea of ftplib is to assist in the task of ftp file transfers. This tutorial shows how to place / upload a file using ftp as well as how to download a file via ftp in Python.
Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/
Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex
Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Python for Data
View skill →
🎓
Tutor Explanation
DeepCamp AI