Skip to content

Commit b2beb8d

Browse files
authored
Merge pull request #209 from DeepakNautiyal987/master
File Transfer Protocols
2 parents b26998f + c522dda commit b2beb8d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: File_Transfer_Protocol/ftp_send_receive.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
File transfer protocol used to send and receive files using FTP server.
3+
Use credentials to provide access to the FTP client
4+
5+
Note: Do not use root username & password for security reasons
6+
Create a seperate user and provide access to a home directory of the user
7+
Use login id and password of the user created
8+
cwd here stands for current working directory
9+
"""
10+
11+
from ftplib import FTP
12+
ftp = FTP('xxx.xxx.x.x') """ Enter the ip address or the domain name here """
13+
ftp.login(user='username', passwd='password')
14+
ftp.cwd('/Enter the directory here/')
15+
16+
"""
17+
The file which will be received via the FTP server
18+
Enter the location of the file where the file is received
19+
"""
20+
21+
def ReceiveFile():
22+
FileName = 'example.txt' """ Enter the location of the file """
23+
LocalFile = open(FileName, 'wb')
24+
ftp.retrbinary('RETR ' + filename, LocalFile.write, 1024)
25+
ftp.quit()
26+
LocalFile.close()
27+
28+
"""
29+
The file which will be sent via the FTP server
30+
The file send will be send to the current working directory
31+
"""
32+
33+
def SendFile():
34+
FileName = 'example.txt' """ Enter the name of the file """
35+
ftp.storbinary('STOR ' + FileName, open(FileName, 'rb'))
36+
ftp.quit()

0 commit comments

Comments
 (0)