Script to extract files info from ftp server [Solved/Closed]

aiko27 - Sep 22, 2008 at 04:53 PM - Latest reply:  Serk5000
- Aug 22, 2010 at 02:04 AM
Hi

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?

Many thanks in advance!!
See more 

11 replies

Best answer
45
Thank you
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 Settings\Nathan\My Documents\2\dRMed\Invoice_RMed.txt"
localPatientFile = "C:\Documents and Settings\Nathan\My Documents\2\dRMed\Patient_RMed.txt"

'specify the file path and name on the remote machine
remoteInvoiceFile = "C:\Clients\Strat\File Uploads\Customer Uploads\RMed\Invoice_RMed.txt"
remotePatientFile = "C:\Clients\Strat\File Uploads\Customer Uploads\RMed\Patient_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

Thank you, cb4nd17 45

Something to say? Add comment

CCM has helped 1706 users this month

See all MSDN scripts samples.
Everything is there
I have to write a script in shell.down load the files from FTP which are updated on month of january, April, aug, december.how I write this in shell scripting.plz give me the solution.
I have to write a script in shell.down load the files from FTP which are updated on month of january, April, aug, december & how I run the job every 1st week of each quarterhow I write this in shell scripting.plz give me the solution.
Would similar scripting work for local worstations whereby the objective is to extract logon logoff information from a csv or bat file?

Let us say that you have user1 user 2 and user3 (registered in Windows environment)
Extracting their logon/logoff sessions seems to cause several issues when the goal is to eliminate other useless info from windows generated log events:

Looking for output in the format:

User: T1 Computer: C1 Date: 02/14/2009 Logon: 9:00 Logoff: 14:00
...
User: Tn Computer: Cn Date: 02/16/2009 Logon: 11:00 Logoff: 18:00
Hi please give me the full script
12
Thank you
If it's under Windows, you must use win32 api
You can ask on specialized Win32 api newsgroup :
news://194.177.96.26/comp.os.ms-windows.programmer.win32
6
Thank you
hi please give me the script
0
Thank you
hi

i want to display directories and its files with size present in ftp site without downloading any of file or directory.
0
Thank you
i am using english language and if you have account information (ftp account information) type to places I tell you

@echo off
echo user USERNAME>ftpcmd.dat
echo PASSWORD>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo lcd>>ftpcmd.dat
echo bell>>ftpcmd.dat
echo ls YOURFTPSERVERSNAME.com>>ftpcmd.dat
echo Expect a loud beep after every transfer!!!
pause
ftp -n -s:ftpcmd.dat YOURFTPSERVERSNAME.com

Copy and Paste this in to notepad and save as whatever.bat

change 'YOURFTPSERVERSNAME.com into your ftp servers name
change 'USERNAME' to your username and change 'PASSWORD' to your password

if anyone can tell how to get into passive mode in ftp using batch

Thanks