from ftplib import FTP import os ftp = FTP() ftp.set_debuglevel(2) ftp.connect("123.126.34.27", "12221") for i in range(1): try: ftp.login("TTuser7017", "791241") print "ok" except: print "no" print ftp.getwelcome() print "****************come in path" ftp.cmd("/tmp/") ftp.retrlines('LIST') ftp.cwd("") print "************ show file" ftp.dir('/tmp/') print "**********show now dir" ftp.pwd() print "*************show filler file" ftp.nlst bufsize = 1024 filename = "long1.xlsx" file_handle = open("/root/long.xlsx", "rb") down_file = open("./down", "wb").write #ftp.storbinary('STOR %s' % os.path.basename(filename),file_handle,bufsize) ftp.storbinary('STOR /home/main_admin/long.txt', file_handle, bufsize) ftp.retrbinary("RETR %s" % os.path.basename(filename), down_file, bufsize)
def callback(line): file = FtpFile(pwd, line) if file.isFtp: ss[file.name]=file return callback ss = dict() ftp.cwd('.') ftp.dir(getCallback(ss, ftp.pwd())) ftp.cwd('新文件夹') ftp.dir(getCallback( ss, ftp.pwd())) for key, value in ss.items(): print('pwd={} name={} isdir={}'.format(value.pwd, value.name, value.isDir)) time.sleep(2) ftp.quit() ftp.close() exit(0) ftp.cmd("xxx/xxx") # 进入远程目录 bufsize = 1024 # 设置的缓冲区大小 filename = "filename.txt" # 需要下载的文件 file_handle = open(filename, "wb").write # 以写模式在本地打开文件 ftp.retrbinaly("RETR filename.txt", file_handle, bufsize) # 接收服务器上文件并写入本地文件 ftp.set_debuglevel(0) # 关闭调试模式 ftp.quit() while True: # sftp.put('text1', '/home/pi/python_code/python_ssh/socketsever.py') # sftp.get('remove_path', 'local_path') # print( '\n,'.join([str(item) for item in ANDROID_FILE_CONFIG.values()])) time.sleep(20)
# coding: utf-8 from ftplib import FTP import time import tarfile import os from ftplib import FTP #加载ftp模块 ftp = FTP() #设置变量 ftp.set_debuglevel(2) #打开调试级别2,显示详细信息 ftp.connect("http://10.111.3.22/", 21) #连接的ftp sever和端口 ftp.login("Administrator", "1q2w3e$R") #连接的用户名,密码 print(ftp.getwelcome()) #打印出欢迎信息 ftp.cmd("e:\engine") #进入远程目录 bufsize = 1024 #设置的缓冲区大小 filename = "john.txt" #需要下载的文件 file_handle = open(filename, "wb").write #以写模式在本地打开文件 ftp.retrbinaly("RETR filename.txt", file_handle, bufsize) #接收服务器上文件并写入本地文件 ftp.set_debuglevel(0) #关闭调试模式 ftp.quit() #退出ftp # from ftplib import FTP # # def ftpconnect(host, username, password): # ftp = FTP() # # ftp.set_debuglevel(2) # ftp.connect(host, 21) # ftp.login(username, password) # return ftp # # #从ftp下载文件