Esempio n. 1
0
ftplib module hides most of this protocol's details.  Change for your site/file.
"""

import os, sys
from getpass import getpass                   # hidden password input
from ftplib import FTP                        # socket-based FTP tools

nonpassive  = False                           # force active mode FTP for server?
filename    = 'monkeys.jpg'                   # file to be downloaded
dirname     = '.'                             # remote directory to fetch from
sitename    = 'ftp.rmi.net'                   # FTP site to contact
userinfo    = ('lutz', getpass('Pswd?'))      # use () for anonymous
if len(sys.argv) > 1: filename = sys.argv[1]  # filename on command line?

print('Connecting...')
connection = FTP(sitename)                  # connect to FTP site
connection.login(*userinfo)                 # default is anonymous login
connection.cwd(dirname)                     # xfer 1k at a time to localfile
if nonpassive:                              # force active FTP if server requires
    connection.set_pasv(False)

print('Downloading...')
localfile = open(filename, 'wb')            # local file to store download
connection.retrbinary('RETR ' + filename, localfile.write, 1024)
connection.quit()
localfile.close()

if input('Open file?') in ['Y', 'y']:
    from PP4E.System.Media.playfile import playfile
    playfile(filename)
Esempio n. 2
0
#!/usr/local/bin/python
"""
Fetch and play the Monty Python theme song. 
Requires Internet access and an FTP account. Uses audio filters
on Unix and the .au player on Windows.
- Configure getfile.py as needed for platform.
"""

from getpass import getpass
from PP4E.Internet.Ftp.getfile import getfile
from PP4E.System.Media.playfile import playfile

file = "sousa.au"
site = "ftp.rmi.net"
dir = "."
user = ("lutz", getpass("Pswd?"))

getfile(file, site, dir, user)
playfile(file)

# import os
# os.system("getone.py sousa.au")



Esempio n. 3
0
#!/usr/local/bin/python
"""
在脚本中使用getfile
A Python script to download and play a media file by FTP.
Uses getfile.py, a utility module which encapsulates FTP step.
"""

import getfile
from getpass import getpass
filename = 'monkeys.jpg'

# fetch with utility
getfile.getfile(file=filename,
                site='ftp.rmi.net',
                dir ='.',
                user=('lutz', getpass('Pswd?')),
                refetch=True)

# rest is the same
if input('Open file?') in ['Y', 'y']:
    from PP4E.System.Media.playfile import playfile
    playfile(filename)
Esempio n. 4
0
#!/usr/local/bin/python
"""
Usage: sousa.py.  Fetch and play the Monty Python theme song.
This will not work on your system as is: it requires a machine with Internet access
and an FTP server account you can access, and uses audio filters on Unix and your
.au player on Windows.  Configure this and playfile.py as needed for your platform.
"""

from getpass import getpass
from PP4E.Internet.Ftp.getfile import getfile
from PP4E.System.Media.playfile import playfile

file = 'sousa.au'  # default file coordinates
site = 'ftp.rmi.net'  # Monty Python theme song
dir = '.'
user = ('lutz', getpass('Pswd?'))

getfile(file, site, dir, user)  # fetch audio file by FTP
playfile(file)  # send it to audio player

# import os
# os.system('getone.py sousa.au')      # equivalent command line
Esempio n. 5
0
File: sousa.py Progetto: bjshan/pp4e
#!/usr/bin/python
"""
Usage: sousa.py. Fetch and play the Monty Python theme song.
This will not work on your system as is: it requires a machine with Internet access
and an FTP server account you can access, and uses audio filters on Unix and your
.au player on Windows. Configure this and playfile.py as needed for your platform.
"""

from getpass import getpass
from PP4E.Internet.Ftp.getfile import getfile
from PP4E.System.Media.playfile import playfile

file = 'sousa.au'		# default file coordinates
site = 'ftp.rmi.net'		# Monty Python theme song
dir = '.'
user = ('lutz', getpass('Pswd?'))

getfile(file, size, dir, user)	# fetch audio file by FTP
playfile(file)			# send it to audio player

# import os
# os.system('getone.py sousa.au')	# equivalent command line
Esempio n. 6
0
# Se devemos acessar os arquivos no modo passivo
# ou no modo ativo
if nonpassive:
    conexão.set_pasv(False)

# Iniciamos o download do arquivo
print('Baixando...')

# Abrimos um novo arquivo para armazenar as informações dos
# arquivos que estamos baixando
with open(nome_arquivo, 'wb') as arquivo_local:
    # Armazena informações do arquivo original no arquivo local

    # Colocamos a string 'RETR ' que indica o comando de download
    # para o FTP

    # retrbinary indica que estamos baixando o arquivo no modo
    # binário, poderíamos baixar o arquivo usando retrlines que baixa
    # o arquivo em ASCII
    conexão.retrbinary('RETR ' + nome_arquivo, arquivo_local.write, 1024)

    # Fechamos a conexão
    conexão.quit()

# Perguntamos se o usuário deseja abrir o arquivo, e se
# a reposta for sim nós o abrimos
if input('Abre Arquivo?').lower().startswith('s'):
    from PP4E.System.Media.playfile import playfile
    playfile(nome_arquivo)
Esempio n. 7
0
#!/usr/local/bin/python

# e.g. 13-6

from getpass import getpass
from PP4E.Internet.Ftp.getfile import getfile
from PP4E.System.Media.playfile import playfile


file = 'sousa.au'

site = 'ftp.rmi.net'
dir = '.'
user = ('lutz', getpass('Pswd?'))

getfile(file, site, dir, user)
playfile(file)