ftp put file on windows using IDL [message #68969] |
Thu, 10 December 2009 10:31  |
natha
Messages: 482 Registered: October 2007
|
Senior Member |
|
|
Hi guys,
I just want to know if it's possible to put a file in a sever via ftp
using IDL. I searched and I found a lot of old posts but actually I
never found something useful. I'm on windows so I can't use SPAWN,
'ftp ....'
Also I read about the SOCKET function but I think it's no possible to
use it for this purpose. Is important to know that the ftp connection
also needs a password.
Thanks in advance for your help,
nata
|
|
|
|
Re: ftp put file on windows using IDL [message #69163 is a reply to message #68969] |
Thu, 10 December 2009 12:12  |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
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
|
|
|
|
Re: ftp put file on windows using IDL [message #69166 is a reply to message #68969] |
Thu, 10 December 2009 10:46  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Thu, 10 Dec 2009, nata wrote:
> Hi guys,
> I just want to know if it's possible to put a file in a sever via ftp
> using IDL. I searched and I found a lot of old posts but actually I
> never found something useful. I'm on windows so I can't use SPAWN,
> 'ftp ....'
> Also I read about the SOCKET function but I think it's no possible to
> use it for this purpose. Is important to know that the ftp connection
> also needs a password.
> Thanks in advance for your help,
> nata
>
There is an IDLnetURL object for HTTP/FTP transfer (in IDL 6.4 or newer).
regards,
Lajos
|
|
|