Remove file extension after successful ftp transfer

requirement: To remove file extension from remote file after succesful automated ftp transfer.

The file is of the form WDC0001.tmp and needs to be changed to WDC0001 on completion of the file transfer.  This is a requierment of the client as they scan the destination folder and process files constantly.  For this reason they do not allow transfer of files without a temporary file extension.

The issue is the number 0001 is a random number and varies for every file that has to be transfered.

The process needs to be automated as the client requires delivery at around 2.30am every day.
We have no issue sending the file. It will be the only file in the source and destination folders. So we can use mput *.tmp to send the file

The difficulty we have is how to remove the file extension from the remote file once it has been delivered.

The machine we are using to send the files is running windows server 2008

So we have access to powershell if needed for scripting.  The server also has a copy of WSFTP_Pro 12 installed if that is of any use.

Does anyone have a suggestion as to how we can achieve this?
vodyanoiAsked:
Who is Participating?
 
AlexPaceCommented:
The problem is knowing if the download was successful or not and only the client knows that for sure so the client should be the one renaming the files.

If the client has Robo-FTP then they could install the following script as a Windows Service and have it always run and monitor the server.  It will automatically download WDC*.tmp files as they appear on the server and only rename them if the download was a success.

:connect
WORKINGDIR "c:\local\download\destination\folder"
FTPLOGON "ftp.vodyanoi.com" /user="vodyanoi" /pw="secret"

:loop 
GETSITEFILE "WDC*.tmp" /timeout=0
IFERROR GOTO error_reset
SET file_name = %sitefile 
SETRIGHT ext = file_name 4 /split 
RCVFILE %sitefile /as file_name
IFERROR GOTO error_reset
FTPRENAME %sitefile file_name
GOTO loop

:error_reset
FTPLOGOFF
PAUSE /for=60
GOTO top

Open in new window

0
 
NrisimhaCommented:


Here is a the all procedure:

E:\TMP\FTP>ftp example.com
Connected to example.com
220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 16 of 1000 allowed.
220-Local time is now 09:30. Server port: 21.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 You will be disconnected after 15 minutes of inactivity.
User (example.com:(none)): billgates@example.com
331 User billgates@example.com OK. Password required
Password:
230-OK. Current restricted directory is /
230 1015327 Kbytes used (99%) - authorized: 1024000 Kb
ftp> cd wd
250 OK. Current directory is /wd
ftp> put WDC0001.tmp
200 PORT command successful
150 Connecting to port 1790
226-1015432 Kbytes used (99%) - authorized: 1024000 Kb
226-File successfully transferred
226 2.530 seconds (measured here), 41.60 Kbytes per second
ftp: 107945 bytes sent in 1,66Seconds 65,18Kbytes/sec.
ftp> rename WDC0001.tmp WDC0001
350 RNFR accepted - file exists, ready for destination
250 File successfully renamed or moved
ftp>

0
 
NrisimhaCommented:

The file  WDC0001.tmp is on my comuter in folder E:\TMP\FTP.
Then I go to Start-Run and write a CMD and click OK.

Now, it is important to go to the E:\TMP\FTP and press dir *.tmp see your WDC0001.tmp dfile.

 FTP1
0
 
vodyanoiAuthor Commented:
Persuaded the client to work this way.

Tested and it works like a dream.  They just had to get a copy of  Robo-ftp

Many thanks
0
 
AlexPaceCommented:
whoops, that script has a bug ... that last line should say GOTO connect instead.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.