Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1751387
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: Python/Ruby

2015-08-02 11:01:17

sftp

点击(此处)折叠或打开

  1. import getpass
  2. import paramiko

  3. HOSTNAME='localhost'
  4. PORT=22
  5. FILE_PATH='/tmp/test.txt'

  6. def sftp_download(username,password,hostname=HOSTNAME,port=PORT):
  7.     ssh_transport=paramiko.Transport(hostname,port)
  8.     ssh_transport.connect(username=username,password=password)
  9.     sftp_session=paramiko.SFTPClient.from_transport(ssh_transport)
  10.     file_path=input("Enter filepath:") or FILE_PATH
  11.     target_file=file_path.split('/')[-1]
  12.     sftp_session.get(file_path,target_file)
  13.     print("Downloaded file from:%s" %file_path)
  14.     sftp_session.close()

  15. if __name__=='__main__':
  16.     hostname=input("Enter the target hostname") or HOSTNAME
  17.     port=input("Enter the target port:") or PORT
  18.     username=input("Enter your username") or "root"
  19.     password="Netf1n1ty" or getpass.getpass(prompt="Enter your password:")
  20.     sftp_download(username,password,hostname,int(port))
FTP

点击(此处)折叠或打开

  1. import ftplib

  2. FTP_SERVER_URL=yourip
  3. DOWNLOAD_DIR_PATH=yourdir
  4. DONWLOAD_FILE_NAME=filename

  5. def ftp_file_download(path,username,password):
  6.     #open ftp connection
  7.     ftp_client=ftplib.FTP(path,username,password)
  8.     #list the files in the download directory
  9.     ftp_client.cwd(DOWNLOAD_DIR_PATH)
  10.     print("File list at %s:" %path)
  11.     files=ftp_client.dir()
  12.     print(files)
  13.     #download a file
  14.     file_handler=open(DONWLOAD_FILE_NAME,'wb')
  15.     #ftp_cmd='RETR %s ' %DONWLOAD_FILE_NAME
  16.     ftp_client.retrbinary('RETR '+DONWLOAD_FILE_NAME,file_handler.write)
  17.     file_handler.close()
  18.     ftp_client.quit()

  19. if __name__=='__main__':
  20.     ftp_file_download(path=FTP_SERVER_URL,username=youruser,password=yourpass)
ntp

点击(此处)折叠或打开

  1. import ntplib
  2. from time import ctime

  3. HOSTNAME='ntp.ubuntu.com'

  4. def ntpupdate():
  5.     params={}
  6.     client=ntplib.NTPClient()
  7.     response=client.request(HOSTNAME)
  8.     print('Received time: %s' %ctime(response.tx_time))
  9.     print('ref_clock:',ntplib.ref_id_to_text(response.ref_id,response.stratum))
  10.     print('stratum: ',response.stratum)
  11.     print('last_jupdate:',response.ref_time)
  12.     print('offset: %f' %response.offset)
  13.     print('precision: ',response.precision)
  14.     print('root_delay: %.6f' %response.root_delay)
  15.     print('root_dispersion: %.6f' %response.root_dispersion)


  16. ntpupdate()



阅读(1492) | 评论(0) | 转发(0) |
0

上一篇:Ubuntu deb 安装

下一篇:Ubuntu 设置vncserver

给主人留下些什么吧!~~