socket-FTP-client

#!/usr/bin/env python

import socket

import sys

import os

 

HOST,PORT="192.168.2.110",90

c = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

c.connect((HOST,PORT))

 

def recv_all(obj,msg_length):

  raw_result = ''

  while True:

    if msg_length<=4096:

      data =obj.recv(msg_length)

      raw_result +=data

      break

    else:

      data =obj.recv(4096)

      raw_result+=data

      msg_length-=4096

  return raw_result

 

 

while True:

  user_input =raw_input('msg to send::').strip()

  iflen(user_input) == 0:continue

 

  user_cmd =user_input.split()

  if user_cmd[0] =='put':

    iflen(user_cmd) ==2:

     f=file(user_cmd[1],'rb')

      f_size =os.stat(user_cmd[1]).st_size

     c.send("%s %s %s" %(user_cmd[0],user_cmd[1],f_size))

      print 'goingto send...'

     c.sendall(f.read())

      printc.recv(1024)

 

c.close()

 

YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS