ssis package download zip file per date

have an ftp site with multiple zip files that are setup per date such as:

file20120911.zip
file20120910.zip
file20120909.zip
etc..

I'm writing an ssis package to load a csv file that is in the zip files. what i'm having trouble with is downloading the zip file that is today's date as this package will run daily.
so i did the following
1. variable: zipFileName with a value of where i want to download it to: \\servername\share
2. placed a script task to generated the zip file name; readwritevariables: user:zipFileName
script code:
public void Main()
        {
            Dts.TaskResult = (int)ScriptResults.Success;
            string mainVar = Dts.Variables["zipFileName"].Value.ToString(); //\\server\share\file20120911.zip set to given date year month day
            DateTime time = DateTime.Now;
            string format = "20120910"; //"yyyyMMdd";
            mainVar = "file" + format + ".zip";
          Dts.Variables["zipFileName"] = mainVar; //doesn't like this
        }
will that set the variable name to my desired file name?
3. success then goes to the ftp task to download the respected new variable file name: say todays date it would be -- file20120911.zip
4. ftp task - under the file transfer i set the following:
  local parameters
   islocalpathvariable true
   localvariable user::localpath
   overwritefileatdest true
  operation
   operation receive files
   istransferascii false
  remote parameters
   isremotepathvariable true
   remotevariable  user:zipFileName

the ftp task gives an error: variable zipFileName doesnt start with /

how do i get this to generate a file name by ymd format and set it up with the ftp task?
fwstealerAsked:
Who is Participating?
 
Alpesh PatelAssistant ConsultantCommented:
FTP
You can get path as variable and create path + datestamp as file name in expression.
0
 
fwstealerAuthor Commented:
i got the file name right by changing to:

public void Main()
        {
            Dts.TaskResult = (int)ScriptResults.Success;

            string mainVar = Dts.Variables["zipFileName"].Value.ToString();
            DateTime dt = DateTime.Now;
            string format = dt.ToString("yyyyMMdd");
            mainVar = "file" + format + ".zip";
            //Dts.Variables["zipFileName"] = mainVar;
        }

one small part working...
0
 
DcpKingCommented:
1. The easy way might be to ensure that only that file gets put into a specific folder, and then copy out and then delete the file with the FTP task.
2. You want a file with a name like <StringConstant1>20120911<StringConstant2>.
--- The two constant parts can be kept set up in a pair of variables.
--- You can easily set a variable to be today's date, updated whenever the SSIS runs
--- Concatenate these three to give you the file spec - \\servername\share\20120911.zip.

Oh, and if you're referring to the file at the other end of the FTP connection, use UNIX file names - forward slashes, so /share/20120911.zip.
0
 
fwstealerAuthor Commented:
how do i get the ftp task editor to read the value of the variable: zipFileName?
0
 
fwstealerAuthor Commented:
i got it by adding another variable and starting the value with / then setting the ftp task to /zipfilename variable.
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.