Skip to content

Instantly share code, notes, and snippets.

@sfszh
Created January 9, 2014 10:01
Show Gist options
  • Save sfszh/8331955 to your computer and use it in GitHub Desktop.
Save sfszh/8331955 to your computer and use it in GitHub Desktop.
upload file with ftp.
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