二.利用FTP服务器的下载文件

from ftplib import FTP
from os.path import exists def getfile(file,site,dir,user=(),*,verbose=True,refetch=False): #verbose为是否打印信息,refetch为是否重新获取文件
if exists(file) and not refetch:
if verbose: print(file,'already fetched')
else:
if verbose:print('Downloading',file)
local = open(file,'wb')
try:
remote = FTP(site)
remote.login(*user)
remote.cwd(dir)
remote.retrbinary('RETR ' + file, local.write, 1024)
remote.quit()
if verbose: print('Finished')
finally:
local.close() if __name__ == '__main__':
file = 'new_1.py'
dir = '.'
site = '192.168.191.1'
user = ()
getfile(file,site,dir,user)

二.利用FTP服务器的上传文件

import ftplib

def putfile(file,site,dir,user=(),*,verbose=True):
if verbose: print('Uploading',file)
local = open(file,'rb')
remote = ftplib.FTP(site)
remote.login(*user)
remote.cwd(dir)
remote.storbinary('STOR ' + file,local,1024)
remote.quit()
local.close()
if verbose: print('Upload done') if __name__ == '__main__':
file = 'test.py'
dir = '.'
site = '192.168.191.1'
user = ()
putfile(file, site, dir, user)

2.3 利用FTP服务器下载和上传文件的更多相关文章

  1. 2.4 利用FTP服务器下载和上传目录

    利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...

  2. 从Linux服务器下载上传文件

    首先要确定好哪两种的连接:Linux常用的有centors和unbantu两种版本,PC端Mac和Windows 如果在两个Linux之间传输,或Linux和Mac之间传输可以使用scp命令,类似于s ...

  3. 使用MFC提供的Http类下载和上传文件

    1.下载文件 Download(const CString& strFileURLInServer, //待下载文件的URL const CString & strFileLocalF ...

  4. 在XShell中使用sz和rz命令下载和上传文件

    借助XShell,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器 工具/原料   XShell CentOS 6.5 使用sz下载文件   1 输 ...

  5. window系统使用tftp下载和上传文件

    安装tftp32服务器 首先需要安装tftp服务器:tftpd32 , 下载以后的目录如下: tftp使用帮助 命令提示符(cmd): 直接运行tftpd32.exe tftp命令的用法: 关于tft ...

  6. ftp服务器不能上传文件故障

    1.在客户端lftp命令无法put文件 原因:登陆用户无法读写 ftp服务器的文件夹,在服务器上增加权限  chmod 777  即可 还有一种方法:在 vsftp的配置文件里,设置可匿名读写

  7. python+selenium下载和上传文件

    操作浏览器上传文件,先看代码 1 """ 2 * send_keys() 指定文件上传路径. 3 """ 4 from selenium i ...

  8. ansible 通过网络下载和上传文件

    1.通过http下载文件,并且不验证证书 - name: download files by https get_url: url: https://robin.org.cn/test.zip des ...

  9. 【FTP】C# System.Net.FtpClient库连接ftp服务器(下载文件)

    如果自己单枪匹马写一个连接ftp服务器代码那是相当恐怖的(socket通信),有一个评价较高的dll库可以供我们使用. 那就是System.Net.FtpClient,链接地址:https://net ...

随机推荐

  1. C#-----中使用using详解

    1.using指令 using + 命名空间名字 例:using System;        using System.Data; 2.using语句 定义一个范围,在范围结束时处理对象,出了这个范 ...

  2. MSG结构体和WndProc窗口过程详解

    MSG结构体和WndProc窗口过程对于Windows编程非常重要,如果不了解它们,可以说就没有学会Windows编程. MSG结构体 MSG 结构体用来表示一条消息,各个字段的含义如下: typed ...

  3. django 完整日志配置

    django中的log需要在settings.py中配置 import time cur_path = os.path.dirname(os.path.realpath(__file__)) # lo ...

  4. John Deere Service Advisor EDL V2 Diagnostic Kit

    Support Languages: English, French, German, Italian, Portuguese, Russian, Spanish. John Deere Servic ...

  5. Linux sar工具安装使用

    使用sar Sar是后台进程sadc的前端显示工具,安装名为“sysstat”的包后,sadc就会自动从内核收集报告并保存.   安装sar [root@localhost ~]# yum insta ...

  6. 安装GDB-ImageWatch ,在QT中查看图像

    GDB_ImageWatch是在Linux下基于QT编写图像处理程序的调试程序. 由于并非像ImageWatch一样由官方提供,而是在github上以代码的方式进行提供,我们在使用的时候需要自己编译, ...

  7. tomcat下面web应用发布路径配置 ( 即虚拟目录配置 )

    https://blog.csdn.net/AnQ17/article/details/52122236

  8. jQuery validator plugin之概要

    jQuery validator 主页 github地址 demo学习 效果: Validate forms like you've never validated before! 自定义Valida ...

  9. element ui 上传图片

    upload在form模块,在demo的基础上包个form然后action写地址用?&拼接参数即可

  10. [JSTL - fmt] fmt标签格式化日期

    <span ><fmt:formatDate value="${ann.adate }" pattern="yyyy-MM-dd"/>& ...