Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8da22e8

Browse files
committed
added downloading & uploading files in ftp server tutorial
1 parent4f2c207 commit8da22e8

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
8787
-[How to Use Threads to Speed Up your IO Tasks in Python](https://www.thepythoncode.com/article/using-threads-in-python). ([code](python-standard-library/using-threads))
8888
-[How to List all Files and Directories in FTP Server using Python](https://www.thepythoncode.com/article/list-files-and-directories-in-ftp-server-in-python). ([code](python-standard-library/listing-files-in-ftp-server))
8989
-[How to Read Emails in Python](https://www.thepythoncode.com/article/reading-emails-in-python). ([code](python-standard-library/reading-email-messages))
90+
-[How to Download and Upload Files in FTP Server using Python](https://www.thepythoncode.com/article/download-and-upload-files-in-ftp-server-using-python). ([code](python-standard-library/download-and-upload-files-in-ftp))
9091

9192
-###[Using APIs](https://www.thepythoncode.com/topic/using-apis-in-python)
9293
-[How to Automate your VPS or Dedicated Server Management in Python](https://www.thepythoncode.com/article/automate-veesp-server-management-in-python). ([code](general/automating-server-management))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[How to Download and Upload Files in FTP Server using Python](https://www.thepythoncode.com/article/download-and-upload-files-in-ftp-server-using-python)
2+
- To upload a file to a FTP server, consider editing`ftp_file_uploader.py` on your needs and run it.
3+
- To download a file, same in`ftp_file_downloader.py`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
importftplib
2+
3+
FTP_HOST="ftp.dlptest.com"
4+
FTP_USER="dlpuser@dlptest.com"
5+
FTP_PASS="SzMf7rTE4pCrf9dV286GuNe4N"
6+
7+
# connect to the FTP server
8+
ftp=ftplib.FTP(FTP_HOST,FTP_USER,FTP_PASS)
9+
# force UTF-8 encoding
10+
ftp.encoding="utf-8"
11+
# the name of file you want to download from the FTP server
12+
filename="some_file.txt"
13+
withopen(filename,"wb")asfile:
14+
# use FTP's RETR command to download the file
15+
ftp.retrbinary(f"RETR{filename}",file.write)
16+
17+
# quit and close the connection
18+
ftp.quit()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
importftplib
2+
3+
# FTP server credentials
4+
FTP_HOST="ftp.dlptest.com"
5+
FTP_USER="dlpuser@dlptest.com"
6+
FTP_PASS="SzMf7rTE4pCrf9dV286GuNe4N"
7+
8+
# connect to the FTP server
9+
ftp=ftplib.FTP(FTP_HOST,FTP_USER,FTP_PASS)
10+
# force UTF-8 encoding
11+
ftp.encoding="utf-8"
12+
# local file name you want to upload
13+
filename="some_file.txt"
14+
withopen(filename,"rb")asfile:
15+
# use FTP's STOR command to upload the file
16+
ftp.storbinary(f"STOR{filename}",file)
17+
# list current files & directories
18+
ftp.dir()
19+
# quit and close the connection
20+
ftp.quit()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a text file!

‎python-standard-library/listing-files-in-ftp-server/list_files.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
FTP_HOST="ftp.ed.ac.uk"
66
FTP_USER="anonymous"
77
FTP_PASS=""
8-
# FTP_HOST = "192.168.1.1"
9-
# FTP_USER = "admin"
10-
# FTP_PASS = "586290929699"
118

129
# some utility functions that we gonna need
1310
defget_size_format(n,suffix="B"):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp