Script to extract files info from ftp server

April 2017




Issue



Wonder if you could help me with the following please.

I would like to construct a script (in any language whichever it's easiest) which when run, it will log on to an existing ftp server using a generic account and password, then list the files in a specific folder that begins with the string "abc". The file names along with their creation date are then to be extracted on a csv file (or similar). Can any one be able to help me on this please?

Solution


Here is the script:
ftp.Hostname = "ftp.test.com"
ftp.Username = "User"
ftp.Password = "Pass"

' The default data transfer mode is "Active" as opposed to "Passive".
' Change it to Passive by setting the Passive property:
ftp.Passive = 1

' Establish an AUTH SSL secure channel after connection
' on the standard FTP port 21.
ftp.AuthTls = 1

' The Ssl property is for establishing an implicit SSL connection
' on port 990. Do not set it.
ftp.Ssl = 0
' Connect and login to the FTP server.
connectStatus = ftp.Connect()
If (connectStatus <> 1) Then
'MsgBox ftp.LastErrorText
'WScript.Quit
Main = DTSTaskExecResult_Failure
Else
dirStatus = ftp.ChangeRemoteDir("RMed")
If (dirStatus <> 1) Then
'MsgBox ftp.LastErrorText
'WScript.Quit
Main = DTSTaskExecResult_Failure
End If



'MsgBox ftp.getCurrentRemoteDir()

'specify the file path and name on the local machine
localInvoiceFile = "C:Documents and SettingsNathanMy Documents2dRMedInvoice_RMed.txt"
localPatientFile = "C:Documents and SettingsNathanMy Documents2dRMedPatient_RMed.txt"

'specify the file path and name on the remote machine
remoteInvoiceFile = "C:ClientsStratFile UploadsCustomer UploadsRMedInvoice_RMed.txt"
remotePatientFile = "C:ClientsStratFile UploadsCustomer UploadsRMedPatient_RMed.txt"
'MsgBox remoteInvoiceFile
'MsgBox remotePatientFile

'download the files from the remote server
transferStatus = ftp.getFile(remoteInvoiceFile, localInvoiceFile)
if (transferStatus <> 1) then
'MsgBox ftp.LastErrorText
Main = DTSTaskExecResult_Failure
else
Main = DTSTaskExecResult_Success
end if

transferStatus = ftp.GetFile(remotePatientFile, localPatientFile)
if (transferStatus <> 1) then
'MsgBox ftp.LastErrorText
Main = DTSTaskExecResult_Failure
else
Main = DTSTaskExecResult_Success
end if

END IF
ftp.Disconnect

End Function

Note


Thanks to cb4nd17 for this tip on the forum.

Related


Published by aakai1056. Latest update on November 30, 2009 at 05:03 AM by aakai1056.
This document, titled "Script to extract files info from ftp server," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).