A simple Guide to FTP
A simple Guide to FTP connection
FTP
The File Transfer Protocol (FTP) is a standard network protocol used to transfer computer files between a client and server on a computer network. FTP is built on a client-server model architecture and uses separate control and data connections between the client and the server.
The client can send FTP commands such as STAT, PWD, RETR, and STOR. The ftplib module has multiple methods that can wrap these commands.
Example
Create a send_command.py script and write the following content in it:
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
import os
import ftplib
ftp_host='xxx'
ftp_user_name='xxx'
ftp_password='xxx'
session = ftplib.FTP(ftp_host,ftp_user_name,ftp_password)
# file to send
file = open('origin_filename.txt','rb')
# send the file
session.storbinary('STOR 'end_filename.txt', file)
# close file and FTP
file.close()
session.quit()
Run the script as follows:
1
2
3
python3 send_command.py