No announcement yet.

Need help with Variables in a FTP script

  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with Variables in a FTP script

    Hi everyone!
    I am trying to create a script that will automate some FTP commands that someone in my company currently has to do manually every day. We have 1-3 files that get put into a directory every night these files always start out as EDI_ then they have a completely random name after that. The problem I am facing is that eventually all three files will need to get renamed on the FTP server to Edirun. This is how out unix system is setup to import the files in. Here is what I need to do with these files:

    1. I need to copy all of these files to an FTP server
    2. I need to rename the files one at a time to Edirun, once the file has been renamed I need to kick off a scripted telnet session (I have written the batch file to perform all the needed telnet commands) This telnet session will import that file into our unix server and rename the Edirun file to it's own naming convention.
    3. Once the first telnet session finishes, I need to perform the above steps on the next file and so on.

    There are not always 3 files sometimes there is only one or two of these EDI_* files. Here is what I done so far:

    I have created a batch file that executes the following command.
    ftp -n -s:G:\edi\ediftp.scr
    The ediftp.scr file is as follows:
    open 10.XXX.XXX.XX
    cd testdata
    mput g:\edi\EDI_*
    what I have so far will get the files copied over just fine, I am having a hard time getting the system to rename the files becuase I do not have a specific filename to tell it. Is it possible to do a rename command with something like EDI_%lastmodified%? I have never really scripted FTP commands before. I would greatly appreciate any help that the community could provide! If you need any further information or if I am making no sense at all please let me know. Thanks!
    A+ Net+ MCP

  • #2
    Re: Need help with Variables in a FTP script

    Found this:
    ftp.exe script - rename multiple files on remote host

    I wrote a script to download multiple files from a 3rd party (working fine). When its done downloading, it should move those files to the "arc" directory in the current directory. Obviously I could delete the files and re-upload them to the other folder but that's unnecessary traffic. It seems the "rename" command is the only way to move files remotely.

    But the "rename" command doesn't seem to support multiple files.
    I tried "rename sar* arc/*" and "rename sar* arc/."
    but both give errors. I've googled this like crazy. Can anyone help?

    The file names contain a date/time stamp and another random number so its difficult to know what the names are.

    Here's the current script:

    open <host>
    lcd R:\JDE\EDI\867\in
    cd in
    cd 867
    mget sar*
    (do move here)

    Accepted answer:

    I suppose once you have downloaded scr*.* to R:\JDE\EDI\867\in you then need to write out an ftp script something like this:

    ftp.exe -s:download.txt
    set script=rename.txt
    echo open >%script%
    echo username >> %script%
    echo password >> %script%
    echo cd in >> %script%
    echo cd 867 >> %script%

    set found=N

    for /f "tokens=*" %%a in ('dir /b R:\jde\edi\867\in\*.*') do set found=Y&echo rename %%a arc/%%a >> %script%

    if "%found%"=="N" goto NODATA

    echo quit >> %script%
    ftp.exe -s:rename.txt


    --rest of the local file processing here--

    Wow, maybe you should be my pizza delivery man
    Like I said, I'm not fluent with dos scripting, but if I'm reading that right, it'll create myscript.txt that I can run w/ ftp.exe -s:myscript.txt?
    Excellent! That's about it. Thanks for all your help guys!

    Maybe you can use something like this solution in your script??


    This posting is provided "AS IS" with no warranties, and confers no rights.


    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts


    • #3
      Re: Need help with Variables in a FTP script

      Thanks for the reply REMS! I did see that post previously but honestly I was not exactly sure how to implement that script, I am very new to scripting. I try to play around with it and see if I can figure it out. Thanks again!
      A+ Net+ MCP