FTP
FTP
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Connect to a server, change directory and download a file as binary using the FTP protocol. Use passive mode if available.
Python 2
<lang Python> from ftplib import FTP ftp = FTP('kernel.org') ftp.login() ftp.cwd('/pub/linux/kernel') ftp.set_pasv(True) # Default since Python 2.1 print ftp.retrlines('LIST') print ftp.retrbinary('RETR README', open('README', 'wb').write) ftp.quit() </lang>
REBOL
<lang REBOL> system/schemes/ftp/passive: on print read ftp://kernel.org/pub/linux/kernel/ write/binary %README read/binary ftp://kernel.org/pub/linux/kernel/README </lang>
Tcl
<lang Tcl> package require ftp
set conn [::ftp::Open kernel.org anonymous "" -mode passive]
- ftp::Cd $conn /pub/linux/kernel
foreach line [ftp::NList $conn] {
puts $line
}
- ftp::Type $conn binary
- ftp::Get $conn README README
</lang>