-
- from ftplib import FTP
-
- def ftpconnect()
- ftp_server = 'ftp.python.org'
- username = '*****'
- password = ******''
- ftp=FTP()
- ftp.set_debuglevel(2)
- ftp.connect(ftp_server,21)
- ftp.login(username,password)
- return ftp
-
- def downloadfile()
- remotepath = "/home/pub/dog.jpg";
- ftp = ftpconnect()
- print ftp.getwelcome()
- bufsize = 1024
- localpath = 'f:\\test\\dog.jpg'
- fp = open(localpath,'wb')
- ftp.retrbinary('RETR ' + remotepath,fp.write,bufsize)
- ftp.set_debuglevel(0)
- fp.close()
- ftp.quit()
- <br>
- def uploadfile()
-
- remotepath = "/home/pub/dog.jpg"
- ftp = ftpconnect()
- bufsize = 1024
- localpath = 'f:\\test\\dog.jpg'
- fp = open(localpath,'rb')
- ftp.storbinary('STOR '+ remotepath ,fp,bufsize)
- ftp.set_debuglevel(0)
- fp.close()
- ftp.quit()
- <br>
- <br>
-
- <pre name="code" class="python"></pre>
- <pre></pre>
- <pre></pre>
-
|