Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName
Dim strLocalFolderName, strFTPServerName, strLoginID, strFTPServerDir
Dim strPassword, strFTPServerFolder, objPassword, objFolder,FolderContent, fso, CleanPath, file, Flag
' Change this, foldername = local dir (where files must be ftp'd TO)
strLocalFolderName = "c:\Temp\test"
' Server where you are ftp'ing TO
strFTPServerName = "<servername>"
' Username you use to ftp
strLoginID = "<username>"
' Initialize variables
strPassword = ""
strFTPServerDir = ""
' Change this to the folder where the files are on the source server
strFTPServerFolder = "/tmp"
'The follow lines of code generate the FTP script file on the fly,
'because the directory name changes every time its run
strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile(strFTPScriptFileName)
End If
Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
'objMyFile.WriteLine ("ftp -s open " & strFTPServerName)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
strPassword = InputBox("Please enter your password:")
objMyFile.WriteLine (strPassword)
'strFTPServerDir = InputBox("Enter directory from which to ftp:")
'objMyFile.WriteLine ("cd " & strFTPServerFolder & strFTPServerDir)
objMyFile.WriteLine ("cd " & strFTPServerFolder)
'objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("get myfile.txt")
objMyFile.WriteLine ("bye")
objMyFile.Close
Set objFSO = Nothing
Set objMyFile = Nothing
'The following code executes the FTP script. It creates a Shell
'object and run FTP program on top of it.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run ("ftp -s:" & chr(34) & strFTPScriptFileName & chr(34))
'objShell.Run (strFTPScriptFileName & chr(34))
Set objShell = Nothing
Set fso=CreateObject("Scripting.FileSystemObject")
CleanPath="c:\temp\test"
For Each file In fso.GetFolder(strLocalFolderName).Files
Flag = StrComp(file, strFTPScriptFileName ,1)
if Flag = 0 then
file.delete
end if
Next