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.
Post here if you experience file transfer problems or unexpected errors.
Here is my script

FTP Script
  1. # Get parameters
  2. #   Note:   Parameter 1 is the path to the scriptFTP.exe file
  3. #       Parameter 2 is the scriptFTP script to run
  4. #
  5.     $ftpServer = GETPARAM(3)
  6.     $ftpUser = GETPARAM(4)
  7.     $ftpPassword = GETPARAM(5)
  8.     $ftpLocalDir = GETPARAM(6)
  9.     $ftpFileToSend = GETPARAM(7)
  10.     $ftpRemoteDir = GETPARAM(8)
  11. #
  12. #  Parameter 9 supports *NONE as American Eagle does not want zipped data, where Topgraf (BIOF) does
  13. #
  14.     $ftpFileToZip = GETPARAM(9)
  15. #
  16. #  Parameter 10 supports *NONE, specifiy *NONE is *NONE is specified for parameter 9
  17. #
  18.     $javaJarLocation = GETPARAM(10)
  19.     $logFileName = GETPARAM(11)
  20.     PRINT($logFileName)
  21.    
  22. #  Script Defaults not passed as parameters
  23. #
  24.     $connectAttempts = GETPARAM(12)
  25.     $waitTimer = GETPARAM(13)
  26.  
  27. # Set Logfile using next number parameter
  28.  
  29.     $result = LOGTO($logFileName)
  30.     IF ($result!="OK")
  31.         GOTO :ERROR
  32.     END IF         
  33.    
  34.     $attempts = 0
  35.        
  36. # Connect to the FTP server using
  37. # the values stored in the variables.
  38. # The value returned from OPENHOST is
  39. # stored in the variable $resultvalue.
  40.     :CONNECT
  41.    
  42.     $attempts = $attempts + 1
  43.     PRINT("Connecting...  Attempt number ".$attempts)
  44.  
  45.     $result=OPENHOST($ftpServer,$ftpUser,$ftpPassword)
  46.     IF ($result != "OK")
  47.         IF ($attempts >= $connectAttempts)
  48.             GOTO :ERROR
  49.         ELSE
  50.             PRINT("Cannot connect! Wait ".$waitTimer." seconds and try again.")
  51.             SLEEP($waitTimer)
  52.             GOTO :CONNECT
  53.         END IF
  54.     END IF
  55.  
  56.     $result=LOCALCHDIR($ftpLocalDir)
  57.     IF ($result != "OK")
  58.         GOTO :ERROR
  59.     END IF         
  60.    
  61.     IF($ftpRemoteDir != "*NONE")
  62.         CHDIR($ftpRemoteDir)
  63.         IF ($result != "OK")
  64.             GOTO :ERROR
  65.         END IF
  66.     END IF
  67.    
  68.     IF ($ftpFileToZip != "*NONE")
  69.         $command = "del ".$ftpFileToZip
  70.         EXEC($command)
  71.         $command = $javaJarLocation."/jar -cfM ".$ftpFileToZip." ".$ftpFileToSend
  72.         $result = EXEC($command)
  73.         IF ($result != "OK")
  74.             PRINT("Java jar RESULT =".$result)
  75.             GOTO :ERROR
  76.         END IF
  77.         $ftpFileToSend = $ftpFileToZip
  78.     END IF
  79.  
  80.     $result = PUTFILE($ftpFileToSend)
  81.     IF($result != "OK")
  82.         PRINT("PUTFILE Error = ".$result)
  83.         GOTO :ERROR
  84.     END IF     
  85.    
  86.     CLOSEHOST
  87.    
  88.     PRINT("")
  89.     PRINT("SUCCESS:  AE FTP File PUT Transfer Completed")  
  90.     PRINT("")
  91.     GOTO :THE_END
  92.  
  93.     :ERROR
  94.     PRINT("")
  95.     PRINT("")
  96.     PRINT("********************************************************************")
  97.     PRINT("ERROR:  AE FTP File PUT Transfer Failed")
  98.     PRINT("********************************************************************")
  99.     PRINT("")
  100.     PRINT("")
  101.    
  102.     :THE_END
  103.     EXIT
Here is the resulting log

Connecting... Attempt number 1

OPENHOST("ftp.americaneagle.com","userid",******)
Connecting to ftp.americaneagle.com
Connected.

LOCALCHDIR("E:\UserExport\AmericanEagle")
Changing current local directory to E:\UserExport\AmericanEagle

PUTFILE("ITEMS.txt")
Uploading................. ITEMS.txt
***** PUTFILE Error #17450: Cannot rename the uploaded file from ITEMS.txt.part to ITEMS.txt.
***** The server said: Rename Failed: File locked

PUTFILE Error = 17450


********************************************************************
ERROR: AE FTP File PUT Transfer Failed
********************************************************************

What's going wrong?
Last edited by stank1964 on 14 Sep 2012, 16:37, edited 1 time in total.
Hello,

Try putting this in the top of your script file:
FTP Script