wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
...untar the file and grab the Lib/ftplib.py file.
You can then do:
from ftplib import FTP_TLS ftps = FTP_TLS('ftp.mysite.com') ftps.login('userid', 'pw') ftps.prot_p() ftps.retrlines('LIST')
To download a file, you would do:
ftps.retrbinary('RETR file.bin', open('output.bin', 'wb').write)
or to upload a file, you would do something on the order of (borrowed from http://www.daniweb.com/software-development/python/threads/110195)
def upload(ftp, file): ext = os.path.splitext(file)[1] if ext in (".txt", ".htm", ".html"): ftp.storlines("STOR %s" % (file), open(file)) else: print ftp.storbinary("STOR %s" % (file), open(file, "rb"), 1024)
Thx !!!
ReplyDeletenice to know, thx!
ReplyDeleteI have written a program similar to yours but I am not getting the file copied,
ReplyDeletedef upload(ftp, file):
ext = os.path.splitext(file)[1]
if ext in (".txt", ".htm", ".html"):
ftp.storlines("STOR %s" % (file), open(file))
else:
print ftp.storbinary("STOR %s" % (file), open(file, "rb"), 1024)
upload(ftp, "VOSS7K.0.0.0.0int691.tgz")
when i login to the switch and search for it shows:
VSP7254-1:1#ls VOSS7K.0.0.0.0int691.tgz
-rw-r--r-- 1 0 0 0 Aug 8 01:14 VOSS7K.0.0.0.0int691.tgz