Error trying to access ftp.debian.org using Python script: "Oserror: [Errno 101] Network is unreachable"

Asked

Viewed 118 times

0

The script:

import os
from getpass import getpass #nao ecoa o que digita na tela!
from ftplib import FTP

# Variavél que determina se devemos usar o modo ativo
# para FTP
nonpassive = False

# Nome do arquivo a ser baixado
nome_arquivo = 'README.html'

# Nome do diretório a ser acessado
dir_nome = 'debian'

# Nome do site a ser acessado, pode ser um domínio ou
# endereço de IP
site_nome = 'ftp.debian.org'

# Poderíamos pegar um usuário e senha para conectar
# no servidor
# usuario_info = ('lutz', getpass('Senha?'))
usuario_info = []

# Iniciamos a conexão
print('Conectando...')

# Criamos a conexão com o servidor do tipo FTP
# através do objeto FTP que recebe o endereço do
# servidor como argumento
conexão = FTP(site_nome)

# Fazemos o login com as informações do usuário
# Poderíamos utilizar o login sem nenhum argumento
# e desta forma estaríamos entrando no servidor
# anonimamente
conexão.login(*usuario_info)

# Acessamos um determinado diretório
conexão.cwd(dir_nome)

# Podemos listar os conteúdos do diretório corrente
# utilizando o método retrlines e passando para ele
# o comando LIST
print(conexão.retrlines('LIST'))

# 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)

ftp.debian.org is browser accessible! I am using Backbox Linux 5.1 x64 When running the script, I get:

TheSError: [Errno 101] Network is unreachable

Any idea how to solve?

  • I tried to enter the normal ftp but it does not answer, I do not know explain the reason but it seems that this FTP works only in the HTTP protocol. You may have another way to access it from FTP. ftp> open ftp.debian.org ftp: Can't connect to ftp.debian.org'``

  • @David Dias: I’ve tried several Ftps that work by the browser but not by the script. I can’t explain!

  • 1

    It’s because Subdomain is called ftp, it doesn’t mean there’s an FTP service running, you know? But it is quite likely that there is some host that will answer in the way you want, or else another port other than 21.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.