Last active
December 19, 2015 08:59
-
-
Save minustore/a6fde8d9bb0edbcf9538 to your computer and use it in GitHub Desktop.
simple upload all files in current dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
import ftplib | |
#uploadList = sys.argv[1:] | |
ipaddress = "xx.xx.xx" | |
port = "21" | |
username = "username" | |
passwd = "passwd" | |
def uploadfile(filepath,filename): | |
file_handle=open(filepath,"rb") | |
ftp.storbinary('STOR '+ filename, file_handle) | |
def getFiles(myPath): | |
'''get list of files with an optional (list of) extension(s) from a folder''' | |
allFiles = [] | |
allFilenames = [] | |
l = os.listdir(myPath) | |
''' if myPath == './' change it to abs path ''' | |
if myPath == "./": | |
myPath = os.getcwd() | |
for myFileName in l: | |
# don't upload itself | |
if myFileName == "ftpupload.py": | |
continue | |
filepath = os.path.join(myPath, myFileName) | |
# only get files,don't get dir | |
if os.path.isfile(filepath): | |
allFiles.append(myFileName) | |
return allFiles | |
ftp = ftplib.FTP() | |
ftp.set_debuglevel(2) | |
ftp.connect(ipaddress, port) | |
ftp.login(username,passwd) | |
print ftp.getwelcome() | |
files = getFiles('./') | |
for onefile in files: | |
uploadfile(onefile,onefile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment