Created
January 9, 2014 10:01
-
-
Save sfszh/8331955 to your computer and use it in GitHub Desktop.
upload file with ftp.
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
import os | |
import paramiko, base64 | |
""" only add file here, if you delete file in the client, server wont delete | |
""" | |
luaRoot = './www/game/test/luaRoot/' | |
def LoginServer(serverRoot, username, psw): | |
transport = paramiko.Transport((serverRoot,22)) | |
transport.connect(username = username, password = psw) | |
sftp = paramiko.SFTPClient.from_transport(transport) | |
#sftp.put('./foobar.txt', luaRoot+'/foo/foobar.txt') | |
print 'finish' | |
UploadFile('.',sftp) | |
sftp.close() | |
transport.close() | |
# ftpSession = ftplib.FTP(serverRoot,id,psw) | |
# print(FTP.pwd()) | |
# ftpSession.quit() | |
def Test(rootDir): | |
for filename in os.listdir(rootDir): | |
path = os.path.join(rootDir, filename) | |
def UploadFile(rootDir, sftp): | |
for lists in os.listdir(rootDir): | |
path = os.path.join(rootDir, lists) | |
serverPath = luaRoot +path[2:].replace("\\","/") | |
#print("upload: "+ serverPath) | |
if os.path.isdir(path): | |
try: | |
sftp.chdir(serverPath) | |
except IOError: | |
sftp.mkdir(serverPath) | |
sftp.chdir('/home/download') | |
UploadFile(path,sftp) | |
if ".py" not in path: | |
if not os.path.isdir(path): | |
#print('aaaa' + sftp.getcwd()) | |
sftp.put(path,serverPath) | |
if __name__ == '__main__': | |
# Test('.') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment