In article
<7f8ef6bd-2c9a-4056-b5c6-9d56025fae45@c3g2000yqd.googlegroups.com>,
nata <bernat.puigdomenech@gmail.com> wrote:
> Ok I see... The documentation in the manual is not very good so I'll
> appreciate some code examples. If not, don't worry, it's always a good
> time to learn.
> nata
Here is an IDLnetURL wrapper that handles the basics of putting
or getting a file with ftp. I haven't used it in a while, but
I think it works.
Ken Bowman
PRO FTP_FILE_KPB, host, remote_url, local_file, username, password, $
PUT = put, $
PASSIVE = passive, $
VERBOSE = verbose
; NAME:
; FTP_FILE_KPB
; PURPOSE:
; FTP a file to or from a remote server by using the IDLnetUrl
; object. The default behavior is to get a file from the
; remote host. To put a file, set the /PUT keyword.
; CATEGORY:
; Network utility.
; CALLING SEQUENCE:
; FTP_FILE_KPB, host, local_file, remote_url, username, password
; INPUT:
; host : host name (:// is automatically added to the hostname)
; remote_url : remote file name
; local_file : path to local file
; username : login name to use with FTP server
; password : password to use wtih FTP server
; OUTPUT:
; If /PUT is not set, a local file is retrieved from the remote host.
; KEYWORDS:
; PUT : If set, put a local file to the remote host. The default behavior
; is to get a remote file from the remote host.
; PASSIVE : If set, set FTP passive mode.
; VERBOSE : If set, print verbose informational messages.
; MODIFICATION HISTORY:
; Kenneth P. Bowman, 2008-10-02.
;-
COMPILE_OPT IDL2 ;Set compile options
SWITCH N_PARAMS() OF
4 : username = '' ;Default username
5 : password = '' ;Default password
ENDSWITCH
IF KEYWORD_SET(verbose) THEN BEGIN
PRINT, 'Host : ', host
PRINT, 'Remote URL : ', remote_url
PRINT, 'Local file : ', local_file
PRINT, 'Username : ', username
PRINT, 'Password : ', password
ENDIF
CATCH, errorStatus
IF (errorStatus NE 0) THEN BEGIN
CATCH, /CANCEL
PRINT, !ERROR_STATE.msg
netURL_obj -> GetProperty, RESPONSE_CODE = rspCode, $ ;Get properties
RESPONSE_HEADER = rspHdr, RESPONSE_FILENAME = rspFn
PRINT, 'rspCode : ', rspCode
PRINT, 'rspHdr : ', rspHdr
PRINT, 'rspFn : ', rspFn
OBJ_DESTROY, netURL_obj ;Destroy the FTP object
RETURN
ENDIF
netURL_obj = OBJ_NEW('IDLnetUrl') ;Create a new FTP object
netURL_obj -> SetProperty, VERBOSE = KEYWORD_SET(verbose) ;Set verbose property
netURL_obj -> SetProperty, URL_SCHEME = 'ftp' ;Set protocol type
netURL_obj -> SetProperty, URL_HOST = host ;Set remote host
netURL_obj -> SetProperty, URL_PATH = remote_url ;Set remote path
netURL_obj -> SetProperty, URL_USERNAME = username ;Set user name
netURL_obj -> SetProperty, URL_PASSWORD = password ;Set password
IF KEYWORD_SET(passive) THEN $
netURL_obj -> SetProperty, FTP_CONNECTION_MODE = 0 ;Set passive mode
IF KEYWORD_SET(put) THEN $
result = netURL_obj -> PUT(local_file) $ ;Put file
ELSE $
result = netURL_obj -> GET(FILENAME = local_file) ;Get file
OBJ_DESTROY, netURL_obj ;Destroy the FTP object
END
|