ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Need help writing a script? Have any question about ScriptFTP?
I am downloading mulitple files but I don't know their names nor their file extension. Can someone tell me how to download all files with extension and append date and time to local folder after download.

Thanks in advance
Cheers
Hi Luke,

Try something like this:
FTP Script
  1. # Get the current date-time
  2. $datetime=GETTIME(FORMAT0)
  3.  
  4. # Create a local directory with the current date-time as name
  5. LOCALMKDIR("C:\".$datetime)
  6.  
  7. # Change current local directory to the created dir
  8. LOCALCHDIR("C:\".$datetime)
  9.  
  10. # Change current remote directory
  11. CHDIR("/path_to/files/")
  12.  
  13. # Download every file from the FTP server
  14. GETFILE("*.*")
Team,
What I am trying to do is to download *.* files and rename those files with appending time and date using GETLIST cmd. Below is the script and the error message when running.

Thanks in Advance.
Cheers
FTP Script
  1. EXEC('copy "c:\test\download\*.*" c:\test\backup')
  2.  
  3. LOcALCHDIR("C:\test\backup")
  4.  
  5. GETLIST($list,LOCAL_FILES)
  6.  
  7. FOREACH $item IN $list
  8.       $current_date=GETDATE(FORMAT3)
  9.       $result=RENAMEFILE("$item","$item-".$current_date)
  10.  
  11.        
  12.       IF($result=="OK")
  13.               PRINT($list)
  14.       ELSE
  15.               STOP
  16.       END IF
Running C:\Users\skywalker\Desktop\test.ftp

EXEC("copy "c:\test\download\*.*" c:\test\backup")

c:\test\download\first.txt
c:\test\download\fourth.txt
c:\test\download\second.txt
c:\test\download\third.txt
4 file(s) copied.

LOCALCHDIR("C:\test\backup")
Changing current local directory to C:\test\backup

GETLIST(LOCAL_FILES)
Getting file listing of current local directory
Found 4 files.

GETTIME(FORMAT3)
Retrieving current time.

RENAMEFILE("$item","$item-20100201")

***** RENAMEFILE Error #18001: Not connected.
This line contains an error:
FTP Script
  1. $result=RENAMEFILE("$item","$item-".$current_date)
The correct way is:
FTP Script
  1. $result=RENAMEFILE($item,$item."-".$current_date)
I am getting exactly the same error and I have no errors in my code.
RENAMEFILE("130124194207.psc","av_altavista-130124194207.psc")
***** RENAMEFILE Error #18001: Not connected.
The script still continues on and executes all other actions except for the renaming of the files.
FTP Script
  1. #set the local directory
  2. LOCALCHDIR($localdir)
  3.  
  4. #retreive the local list of bak files
  5. $result=GETLIST($list,LOCAL_FILES,"*.". $file_ext)
  6.  
  7. # If GETLIST did not find any files
  8. IF($result!="OK")
  9.        
  10.     PRINT("No New Files Found")
  11.     PRINT("Going to cleanup")
  12.     GOTO :cleanup
  13.         EXIT
  14.    
  15.  
  16. #rename each file with the name of the db
  17. FOREACH $item IN $list
  18.    LOCALCHDIR($localdir)
  19.    PRINT("OLD FILE NAME: " . $item)
  20.    RENAMEFILE($item,$databasename . "-" . $item)
  21.    PRINT("NEW FILE NAME: " . $databasename . "-" . $item)
  22.  
Hello Craig,

Please, use VERBOSE(ON) on the top of your script file and post here what you get just after using RENAMEFILE. This will give me some clues about what is going on