python script to upload file to server

Solutions on MaxInterview for python script to upload file to server by the best coders in the world

showing results for - "python script to upload file to server"
Liya
27 Jul 2017
1## To start:
2
3from ftplib import FTP
4
5# Domain name or server ip:
6ftp = FTP('123.server.ip')
7ftp.login(user='username', passwd = 'password')
8
9## The above will connect you to your remote server. You can then change into a specific directory with:
10
11ftp.cwd('/whyfix/')
12
13## Now, let's show how we might download a file:
14
15def grabFile():
16
17    filename = 'example.txt'
18
19    localfile = open(filename, 'wb')
20    ftp.retrbinary('RETR ' + filename, localfile.write, 1024)
21
22    ftp.quit()
23    localfile.close()
24    
25## Next, how about uploading a file?
26
27def placeFile():
28
29    filename = 'exampleFile.txt'
30    ftp.storbinary('STOR '+filename, open(filename, 'rb'))
31    ftp.quit()
32
33placeFile()