Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move file to new folder

Status
Not open for further replies.

vgwprja

Programmer
Mar 27, 2008
24
0
0
US
I have a FTP script and after the FTP I need to move the file to a backup folder. Not sure how to do this:

Option Explicit

Dim strFTPScriptFileName, colFiles, objFile, objFSO, objMyFile, objShell, objFolder, strFilePut
Dim strLocalFolderName, strFTPServerName, strLoginID
Dim strPassword, strFTPServerFolder

'Set FTP options
strLocalFolderName = "e:\ftpdata\fromcustomer"
strFTPServerName = "ftp.customer.com"
strLoginID = "userid"
strPassword = "password"
strFTPServerFolder = "from_customer"

'Set File name
strFilePut = "*.asc"

'Generate FTP command
strFTPScriptFileName = strLocalFolderName & "\Travelers_Inbound_Get_FTP_Files"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If

Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)

objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("cd " & strFTPServerFolder)
objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("prompt off")
objMyFile.WriteLine ("get " & strFilePut)

*** Here I need to move the file I just picked up to folder:
strFTPServerFolder + /Backup ***

objMyFile.WriteLine ("disconnect")
objMyFile.WriteLine ("bye")
objMyFile.Close
 
METHOD: FileSystemObject.MoveFile

object.MoveFile source, destination

Simi
 
I understand, but how do I get the name of the file I just ftp'ed, this is the one I need to move. Thank you.
 
Could I use something like this:

objMyFile.WriteLine ("move " & objFile.Name, strFTPServerFolder/backup)
 
Hi vgwprja

If this is the file you want to move "strFTPScriptFileName"

Based on your code it's already created from this portion of your code "Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)"

So you should only need to use the "move" method from your object "objFSO"

Like objFso.Movefile(strFTPScriptFileName, destination)

It's used the sdame way you handle the deleting of this file in your code here objFSO.DeleteFile (strFTPScriptFileName)

You can go to "http:\\ and download the primal script2007 software.

This is great for building and learning the properties, Methods and other items with VBscript.

Good luck! [afro]
 
Not sure if we are talking about the same thing (most likely my lack of understanding)

At the line objMyFile.WriteLine ("get " & strFilePut) the script picks up a file (whatevere is in the outgoing ftp folder) and does the ftp. I do not now the file name of the ftp file as it has a date/time stamp. Whatevere it picks up, this is the file I need to move. So my question is where do I get the name of the file I just ftp'ed and do the move.

 
Ohhh! I think I see what you want to do, I see the file you're creating here is the automated FTP script.

You also have an strFilePut "*.asc" if the asc file(s) is the one in question and you want to move this file.

You may want to "Get" this file from the ftp site and pull it onto your local machine.

From there try and move it to the destination you desire

I hope I understand what it is your asking. [2thumbsup]

 
We are getting there, this is an automated script and once I have done the "get" I need to move the file on the remote machine so I do not pick it up again later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top