How to Automatically download csv file from SFTP and upload it to Salesforce using CLI Dataloader, Batch and Window Scheduler ?


So basically the requirement was to automatically download the file from a FTP/SFTP and upload the file in Salesforce Leads. To upload the file we will create a batch and schedule it using Window Scheduler.

To achieve this functionality in short we will create a batch to download the file from FTP/SFTP and save it in our local machine. And then upload it to salesforce Leads using CLI Data Loader.

Please follow below steps : 


STEP : A

  1. Download & Install WinSCP on a window machine.
  2. Connect the FTP/SFTP using credentials.
  3. Go to session → Generate session URL/code.
  4. Check only User Name, Password & Initial directory in the case of FTP.
  5. In the case of SFTP check SSH host key checkbox also.
  6. Copy the generated url.
  7. Create a txt file using following code below : 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Connect

Open URL COPIED FROM STEP 5 

# Change remote directory

cd /

# Download file to the local directory c:\

get fileName.csv c:\TestFolder\

# Disconnect

Close


  1. Save the txt file. My file name is example.txt
  2. Open CMD.
  3. Copy and paste following command :
    "C:\Program Files (x86)\WinSCP\WinSCP.com" /ini=nul /script=C:\TestFolder\example.txt

  1. Hit enter.
  2. The file will be copied from your FTP/SFTP to your window machine.


STEP : B
  1. First of all, make sure you have the Admin rights on the machine.
  2. Then, download the data loader setup file on the machine by going into Salesforce environment Setup –> Data Management –> Data Loader. Choose the option “Download Data Loader for Windows“. It will download the latest version of data loader setup file. Install it by following the setup wizard.
  3. Also, you need to have the required version of JRE (Java Run Time Environment). 
    1. Download the latest JRE version from Oracle site downloads page.
    2. Install the downloaded JRE file.
    3. Please follow steps 1 to 5 from this link below : https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/command_line_intro.htm

STEP : C
  1. Create batch file of commands.
  2. Schedule the task in window scheduler, follow the steps here https://www.thewindowsclub.com/how-to-schedule-batch-file-run-automatically-windows-7

Schedule the batch classes and you are good to go.

 If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Keep Coding 

Post a Comment

0 Comments